update dev300-m58
[ooovba.git] / sc / source / filter / inc / xetable.hxx
blob2beb423bf32ab36323a590aaa7dc7b244da7a85b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xetable.hxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XETABLE_HXX
32 #define SC_XETABLE_HXX
34 #include "xltable.hxx"
36 #include <deque>
37 #include <tools/mempool.hxx>
38 #include "xladdress.hxx"
39 #include "xerecord.hxx"
40 #include "xestring.hxx"
41 #include "xeformula.hxx"
42 #include "xestyle.hxx"
44 /* ============================================================================
45 Export of cell tables including row and column description.
46 - Managing all used and formatted cells in a sheet.
47 - Row and column properties, i.e. width/height, visibility.
48 - Find default row formatting and default column formatting.
49 - Merged cell ranges.
50 ============================================================================ */
52 // ============================================================================
53 // Helper records for cell records
54 // ============================================================================
56 /** Represents a STRING record that contains the result of a string formula. */
57 class XclExpStringRec : public XclExpRecord
59 public:
60 explicit XclExpStringRec( const XclExpRoot& rRoot, const String& rResult );
62 private:
63 virtual void WriteBody( XclExpStream& rStrm );
65 private:
66 XclExpStringRef mxResult;
69 // Additional records for special formula ranges ==============================
71 /** Base record for additional range formula records (i.e. ARRAY, SHRFMLA). */
72 class XclExpRangeFmlaBase : public XclExpRecord
74 public:
75 /** Returns true, if the passed cell position is equal to own base position. */
76 bool IsBasePos( sal_uInt16 nXclCol, sal_uInt16 nXclRow ) const;
78 /** Derived classes create the token array for a corresponding FORMULA cell record. */
79 virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const = 0;
80 /** Derived classes return true, if the own formula contains volatile functions. */
81 virtual bool IsVolatile() const = 0;
83 protected:
84 /** Constructs the record with a single cell. */
85 explicit XclExpRangeFmlaBase(
86 sal_uInt16 nRecId, sal_uInt32 nRecSize, const ScAddress& rScPos );
87 /** Constructs the record with a cell range. */
88 explicit XclExpRangeFmlaBase(
89 sal_uInt16 nRecId, sal_uInt32 nRecSize, const ScRange& rScRange );
91 /** Extends the cell range to include the passed cell address. */
92 void Extend( const ScAddress& rScPos );
94 /** Writes the range address covered by this record. */
95 void WriteRangeAddress( XclExpStream& rStrm ) const;
97 protected:
98 XclRange maXclRange; /// Range described by this record.
99 XclAddress maBaseXclPos; /// Address of base cell (first FORMULA record).
102 typedef ScfRef< XclExpRangeFmlaBase > XclExpRangeFmlaRef;
104 // Array formulas =============================================================
106 class ScTokenArray;
108 /** Represents an ARRAY record that contains the token array of a matrix formula.
110 An ARRAY record is stored following the first FORMULA record that is part
111 of a matrix formula. All FORMULA records of a matrix formula contain a
112 reference to the ARRAY record, while the ARRAY record contains the formula
113 token array used by all formulas.
115 class XclExpArray : public XclExpRangeFmlaBase
117 public:
118 explicit XclExpArray( XclTokenArrayRef xTokArr, const ScRange& rScRange );
120 /** Creates and returns the token array for a corresponding FORMULA cell record. */
121 virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const;
122 /** Returns true, if the array formula contains volatile functions. */
123 virtual bool IsVolatile() const;
125 private:
126 virtual void WriteBody( XclExpStream& rStrm );
128 private:
129 XclTokenArrayRef mxTokArr; /// The token array of a matrix formula.
132 typedef ScfRef< XclExpArray > XclExpArrayRef;
134 // ----------------------------------------------------------------------------
136 /** Caches all ARRAY records. */
137 class XclExpArrayBuffer : protected XclExpRoot
139 public:
140 explicit XclExpArrayBuffer( const XclExpRoot& rRoot );
142 /** Inserts a new ARRAY record into the buffer and returns it. */
143 XclExpArrayRef CreateArray( const ScTokenArray& rScTokArr, const ScRange& rScRange );
144 /** Tries to find an ARRAY record that corresponds to an ocMatRef token. */
145 XclExpArrayRef FindArray( const ScTokenArray& rScTokArr ) const;
147 private:
148 typedef ::std::map< ScAddress, XclExpArrayRef > XclExpArrayMap;
149 XclExpArrayMap maRecMap; /// Map containing the ARRAY records.
152 // Shared formulas ============================================================
154 /** Represents a SHRFMLA record that contains the token array of a shared formula.
156 A SHRFMLA record is stored following the first FORMULA record that is part
157 of a shared formula. All FORMULA records of a shared formula contain a
158 reference to the SHRFMLA record, while the SHRFMLA record contains the
159 formula token array used by all formulas.
161 class XclExpShrfmla : public XclExpRangeFmlaBase
163 public:
164 /** Creates a SHRFMLA record that consists of the passed cell address only. */
165 explicit XclExpShrfmla( XclTokenArrayRef xTokArr, const ScAddress& rScPos );
167 /** Extends the cell range to include the passed cell address. */
168 void ExtendRange( const ScAddress& rScPos );
170 /** Creates and returns the token array for a corresponding FORMULA cell record. */
171 virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const;
172 /** Returns true, if the shared formula contains volatile functions. */
173 virtual bool IsVolatile() const;
175 private:
176 virtual void WriteBody( XclExpStream& rStrm );
178 private:
179 XclTokenArrayRef mxTokArr; /// The token array of a shared formula.
180 sal_uInt8 mnUsedCount; /// Number of FORMULA records referring to this record.
183 typedef ScfRef< XclExpShrfmla > XclExpShrfmlaRef;
185 // ----------------------------------------------------------------------------
187 /** Caches all SHRFMLA records and provides functions to update their ranges. */
188 class XclExpShrfmlaBuffer : protected XclExpRoot
190 public:
191 explicit XclExpShrfmlaBuffer( const XclExpRoot& rRoot );
193 /** Tries to create a new or to update an existing SHRFMLA record.
194 @return An empty reference, if the passed token array does not contain
195 a shared formula. If the token array is a shared formula, this
196 function updates its cell range to include the passed cell position,
197 if there is a SHRFMLA record for the passed token array; otherwise
198 this function creates and returns a new SHRFMLA record. */
199 XclExpShrfmlaRef CreateOrExtendShrfmla(
200 const ScTokenArray& rScTokArr, const ScAddress& rScPos );
202 private:
203 typedef ::std::map< const ScTokenArray*, XclExpShrfmlaRef > XclExpShrfmlaMap;
204 XclExpShrfmlaMap maRecMap; /// Map containing the SHRFMLA records.
207 // Multiple operations ========================================================
209 struct XclMultipleOpRefs;
211 /** Represents a TABLEOP record for a multiple operations range. */
212 class XclExpTableop : public XclExpRangeFmlaBase
214 public:
215 explicit XclExpTableop( const ScAddress& rScPos,
216 const XclMultipleOpRefs& rRefs, sal_uInt8 nScMode );
218 /** Returns true, if the cell range has been extended to the passed position.
219 @descr All references passed in rRefs must fit the ranges passed in the constructor. */
220 bool TryExtend( const ScAddress& rScPos, const XclMultipleOpRefs& rRefs );
222 /** Finalizes the record. Tests on valid cell range and reference addresses. */
223 void Finalize();
225 /** Creates and returns the token array for a corresponding FORMULA cell record. */
226 virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const;
227 /** Returns true, if the multiple operations range is volatile. */
228 virtual bool IsVolatile() const;
229 /** Writes the record if it is valid. */
230 virtual void Save( XclExpStream& rStrm );
232 private:
233 /** Returns true, if the passed cell position can be appended to this record. */
234 bool IsAppendable( sal_uInt16 nXclCol, sal_uInt16 nXclRow ) const;
236 /** Writes the contents of the TABLEOP record. */
237 virtual void WriteBody( XclExpStream& rStrm );
239 private:
240 SCTAB mnScTab; /// Sheet index of this record.
241 sal_uInt16 mnLastAppXclCol;/// Column index of last appended cell.
242 sal_uInt16 mnColInpXclCol; /// Column index of column input cell.
243 sal_uInt16 mnColInpXclRow; /// Row index of column input cell.
244 sal_uInt16 mnRowInpXclCol; /// Column index of row input cell.
245 sal_uInt16 mnRowInpXclRow; /// Row index of row input cell.
246 sal_uInt8 mnScMode; /// Type of the multiple operation (Calc constant).
247 bool mbValid; /// true = Contains valid references.
250 typedef ScfRef< XclExpTableop > XclExpTableopRef;
252 // ----------------------------------------------------------------------------
254 /** Contains all created TABLEOP records and supports creating or updating them. */
255 class XclExpTableopBuffer : protected XclExpRoot
257 public:
258 explicit XclExpTableopBuffer( const XclExpRoot& rRoot );
260 /** Tries to update an existing or to create a new TABLEOP record.
261 @return Reference to the TABLEOP record for this cell (existing or new),
262 or an empty reference, if rScTokArr does not contain a multiple
263 operations formula. */
264 XclExpTableopRef CreateOrExtendTableop(
265 const ScTokenArray& rScTokArr, const ScAddress& rScPos );
267 /** Finalizes all contained TABLEOP records. */
268 void Finalize();
270 private:
271 /** Tries to create a new TABLEOP record, if rRefs contains valid references. */
272 XclExpTableopRef TryCreate( const ScAddress& rScPos, const XclMultipleOpRefs& rRefs );
274 private:
275 typedef XclExpRecordList< XclExpTableop > XclExpTableopList;
276 XclExpTableopList maTableopList; /// List of all TABLEOP records.
279 // ============================================================================
280 // Cell records
281 // ============================================================================
283 /** The base class of all cell records. */
284 class XclExpCellBase : public XclExpRecord
286 public:
287 /** Returns the (first) address of the cell(s). */
288 inline const XclAddress& GetXclPos() const { return maXclPos; }
289 /** Returns the (first) Excel column index of the cell(s). */
290 inline sal_uInt16 GetXclCol() const { return maXclPos.mnCol; }
291 /** Returns the Excel row index of the cell. */
292 inline sal_uInt16 GetXclRow() const { return maXclPos.mnRow; }
294 /** Derived classes return the column index of the last contained cell. */
295 virtual sal_uInt16 GetLastXclCol() const = 0;
296 /** Derived classes return the XF identifier of the first contained cell. */
297 virtual sal_uInt32 GetFirstXFId() const = 0;
298 /** Derived classes return true, if this record does not contain at least one valid cell. */
299 virtual bool IsEmpty() const = 0;
300 /** Derived classes return whether the cell contains multi-line text. */
301 virtual bool IsMultiLineText() const;
303 /** Derived classes try to merge the contents of the passed cell to own data. */
304 virtual bool TryMerge( const XclExpCellBase& rCell );
305 /** Derived classes convert the XF identifier(s) into the Excel XF index(es).
306 @param rXFIndexes The converted XF index(es) are inserted here. */
307 virtual void ConvertXFIndexes( const XclExpRoot& rRoot ) = 0;
308 /** Derived classes for blank cells insert the Excel XF index(es) into the passed vector. */
309 virtual void GetBlankXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
310 /** Derived classes for blank cells remove unused Excel XF index(es). */
311 virtual void RemoveUnusedBlankCells( const ScfUInt16Vec& rXFIndexes );
313 protected:
314 explicit XclExpCellBase(
315 sal_uInt16 nRecId, sal_Size nContSize, const XclAddress& rXclPos );
317 /** Sets this record to a new column position. */
318 inline void SetXclCol( sal_uInt16 nXclCol ) { maXclPos.mnCol = nXclCol; }
319 /** Sets this record to a new row position. */
320 inline void SetXclRow( sal_uInt16 nXclRow ) { maXclPos.mnRow = nXclRow; }
322 private:
323 XclAddress maXclPos; /// Address of the cell.
326 typedef ScfRef< XclExpCellBase > XclExpCellRef;
328 // Single cell records ========================================================
330 /** Base class for all cell records not supporting multiple contents. */
331 class XclExpSingleCellBase : public XclExpCellBase
333 public:
334 /** Returns the last column, which is equal to the first column for single cells. */
335 virtual sal_uInt16 GetLastXclCol() const;
336 /** Return the XF identifier of the cell. */
337 virtual sal_uInt32 GetFirstXFId() const;
338 /** Returns true, if this record does not contain at least one valid cell. */
339 virtual bool IsEmpty() const;
340 /** Converts the XF identifier into the Excel XF index. */
341 virtual void ConvertXFIndexes( const XclExpRoot& rRoot );
342 /** Writes cell address, XF index, and calls WriteContents() for each cell. */
343 virtual void Save( XclExpStream& rStrm );
345 protected:
346 explicit XclExpSingleCellBase( sal_uInt16 nRecId, sal_Size nContSize,
347 const XclAddress& rXclPos, sal_uInt32 nXFId );
349 explicit XclExpSingleCellBase( const XclExpRoot& rRoot,
350 sal_uInt16 nRecId, sal_Size nContSize, const XclAddress& rXclPos,
351 const ScPatternAttr* pPattern, sal_Int16 nScript, sal_uInt32 nForcedXFId );
353 inline void SetContSize( sal_Size nContSize ) { mnContSize = nContSize; }
354 inline sal_Size GetContSize() const { return mnContSize; }
356 inline void SetXFId( sal_uInt32 nXFId ) { maXFId.mnXFId = nXFId; }
357 inline sal_uInt32 GetXFId() const { return maXFId.mnXFId; }
359 private:
360 /** Writes cell address, XF index, and calls WriteContents() for each cell. */
361 virtual void WriteBody( XclExpStream& rStrm );
362 /** Derived classes write the contents of the specified cell (without XF index). */
363 virtual void WriteContents( XclExpStream& rStrm ) = 0;
365 private:
366 XclExpXFId maXFId; /// The XF identifier of the cell formatting.
367 sal_Size mnContSize; /// The size of the cell contents.
370 // ----------------------------------------------------------------------------
372 /** Represents a NUMBER record that describes a cell with a double value. */
373 class XclExpNumberCell : public XclExpSingleCellBase
375 DECL_FIXEDMEMPOOL_NEWDEL( XclExpNumberCell )
377 public:
378 explicit XclExpNumberCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
379 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
380 double fValue );
382 virtual void SaveXml( XclExpXmlStream& rStrm );
383 private:
384 virtual void WriteContents( XclExpStream& rStrm );
386 private:
387 double mfValue; /// The cell value.
390 // ----------------------------------------------------------------------------
392 /** Represents a BOOLERR record that describes a cell with a Boolean value. */
393 class XclExpBooleanCell : public XclExpSingleCellBase
395 DECL_FIXEDMEMPOOL_NEWDEL( XclExpBooleanCell )
397 public:
398 explicit XclExpBooleanCell( const XclExpRoot rRoot, const XclAddress& rXclPos,
399 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
400 bool bValue );
402 virtual void SaveXml( XclExpXmlStream& rStrm );
403 private:
404 virtual void WriteContents( XclExpStream& rStrm );
406 private:
407 bool mbValue; /// The cell value.
410 // ----------------------------------------------------------------------------
412 //UNUSED2009-05 /** Represents a BOOLERR record that describes a cell with an error code. */
413 //UNUSED2009-05 class XclExpErrorCell : public XclExpSingleCellBase
414 //UNUSED2009-05 {
415 //UNUSED2009-05 DECL_FIXEDMEMPOOL_NEWDEL( XclExpErrorCell )
416 //UNUSED2009-05
417 //UNUSED2009-05 public:
418 //UNUSED2009-05 explicit XclExpErrorCell( const XclExpRoot rRoot, const XclAddress& rXclPos,
419 //UNUSED2009-05 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
420 //UNUSED2009-05 sal_uInt8 nErrCode );
421 //UNUSED2009-05
422 //UNUSED2009-05 virtual void SaveXml( XclExpXmlStream& rStrm );
423 //UNUSED2009-05 private:
424 //UNUSED2009-05 virtual void WriteContents( XclExpStream& rStrm );
425 //UNUSED2009-05
426 //UNUSED2009-05 private:
427 //UNUSED2009-05 sal_uInt8 mnErrCode; /// The error code.
428 //UNUSED2009-05 };
430 // ----------------------------------------------------------------------------
432 class ScStringCell;
433 class ScEditCell;
434 class XclExpHyperlinkHelper;
436 /** Represents a text cell record.
438 May contain a BIFF2-BIFF7 LABEL record for a simple string, or a BIFF2-BIFF7
439 RSTRING record for a formatted string, or a BIFF8 LABELSST string for any
440 string (simply stores a reference to the Shared String Table).
442 class XclExpLabelCell : public XclExpSingleCellBase
444 DECL_FIXEDMEMPOOL_NEWDEL( XclExpLabelCell )
446 public:
447 /** Constructs the record from an unformatted Calc string cell. */
448 explicit XclExpLabelCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
449 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
450 const ScStringCell& rCell );
452 /** Constructs the record from a formatted Calc edit cell. */
453 explicit XclExpLabelCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
454 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
455 const ScEditCell& rCell, XclExpHyperlinkHelper& rHlinkHelper );
457 /** Returns true if the cell contains multi-line text. */
458 virtual bool IsMultiLineText() const;
460 virtual void SaveXml( XclExpXmlStream& rStrm );
461 private:
462 /** Initializes the record contents. Called from constructors. */
463 void Init( const XclExpRoot& rRoot,
464 const ScPatternAttr* pPattern, XclExpStringRef xText );
466 virtual void WriteContents( XclExpStream& rStrm );
468 private:
469 XclExpStringRef mxText; /// The cell text.
470 sal_uInt32 mnSstIndex; /// Index into Shared String Table (only used for BIFF8).
471 bool mbLineBreak; /// True = cell has automatic linebreaks enabled.
474 // ----------------------------------------------------------------------------
476 class ScFormulaCell;
478 /** Represents a FORMULA record that describes a cell with a formula. */
479 class XclExpFormulaCell : public XclExpSingleCellBase
481 DECL_FIXEDMEMPOOL_NEWDEL( XclExpFormulaCell )
483 public:
484 explicit XclExpFormulaCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
485 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
486 const ScFormulaCell& rScFmlaCell,
487 XclExpArrayBuffer& rArrayBfr,
488 XclExpShrfmlaBuffer& rShrfmlaBfr,
489 XclExpTableopBuffer& rTableopBfr );
491 /** Writes the FORMULA record and additional records related to the formula. */
492 virtual void Save( XclExpStream& rStrm );
493 virtual void SaveXml( XclExpXmlStream& rStrm );
495 private:
496 virtual void WriteContents( XclExpStream& rStrm );
498 private:
499 ScFormulaCell& mrScFmlaCell; /// The Calc formula cell.
500 XclTokenArrayRef mxTokArr; /// The token array of the formula.
501 XclExpRangeFmlaRef mxAddRec; /// Additional record for matrix/shared formulas.
502 XclExpRecordRef mxStringRec; /// STRING record for string result.
505 // Multiple cell records ======================================================
507 struct XclExpMultiXFId : public XclExpXFId
509 sal_uInt16 mnCount; /// Number of XF identifiers.
511 inline explicit XclExpMultiXFId( sal_uInt32 nXFId, sal_uInt16 nCount = 1 ) :
512 XclExpXFId( nXFId ), mnCount( nCount ) {}
515 // ----------------------------------------------------------------------------
517 /** Base class for all cell records supporting multiple contents. */
518 class XclExpMultiCellBase : public XclExpCellBase
520 public:
521 /** Returns the column index of the last cell this record describes. */
522 virtual sal_uInt16 GetLastXclCol() const;
523 /** Return the XF identifier of the first contained cell. */
524 virtual sal_uInt32 GetFirstXFId() const;
525 /** Returns true, if this record does not contain at least one valid cell. */
526 virtual bool IsEmpty() const;
528 /** Convert all XF identifiers into the Excel XF indexes. */
529 virtual void ConvertXFIndexes( const XclExpRoot& rRoot );
530 /** Writes the record, calls WriteContents() for each contained cell.
531 @descr May write several records, if unused XF indexes are contained. */
532 virtual void Save( XclExpStream& rStrm );
533 virtual void SaveXml( XclExpXmlStream& rStrm );
535 protected:
536 explicit XclExpMultiCellBase( sal_uInt16 nRecId, sal_uInt16 nMulRecId,
537 sal_Size nContSize, const XclAddress& rXclPos );
539 /** Sets the size of the remaining contents of one cell (without the XF index). */
540 inline void SetContSize( sal_Size nContSize ) { mnContSize = nContSize; }
541 /** Returns the size of the remaining contents of one cell (without the XF index). */
542 inline sal_Size GetContSize() const { return mnContSize; }
544 /** Returns the number of cells this record represents. */
545 sal_uInt16 GetCellCount() const;
547 /** Appends the passed XF identifier nCount times to the list of XF identifiers. */
548 void AppendXFId( const XclExpMultiXFId& rXFId );
549 /** Appends the passed cell format nCount times to the list of XF identifiers. */
550 void AppendXFId( const XclExpRoot& rRoot,
551 const ScPatternAttr* pPattern, sal_uInt16 nScript,
552 sal_uInt32 nForcedXFId, sal_uInt16 nCount = 1 );
554 /** Tries to merge the XF ID list of the passed cell with the own list. */
555 bool TryMergeXFIds( const XclExpMultiCellBase& rCell );
556 /** Inserts the Excel XF index(es) into the passed vector. */
557 void GetXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
559 /** Removes unused Excel XF index(es).
560 @param rXFIndexes Specifies which XF indexes are used. */
561 void RemoveUnusedXFIndexes( const ScfUInt16Vec& rXFIndexes );
563 private:
564 /** Derived classes write the remaining contents of the specified cell (without XF index).
565 @param nRelCol Relative column index (starts with 0 for first cell of this record). */
566 virtual void WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol ) = 0;
567 virtual void WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol ) = 0;
569 private:
570 typedef ::std::deque< XclExpMultiXFId > XclExpMultiXFIdDeq;
572 sal_uInt16 mnMulRecId; /// Record ID for multiple record variant.
573 sal_Size mnContSize; /// Data size of contents for one cell
574 XclExpMultiXFIdDeq maXFIds; /// The XF identifiers of the cell formatting.
577 // ----------------------------------------------------------------------------
579 /** Represents a BLANK or MULBLANK record that describes empty but formatted cells. */
580 class XclExpBlankCell : public XclExpMultiCellBase
582 DECL_FIXEDMEMPOOL_NEWDEL( XclExpBlankCell )
584 public:
585 explicit XclExpBlankCell( const XclAddress& rXclPos, const XclExpMultiXFId& rXFId );
587 explicit XclExpBlankCell( const XclExpRoot& rRoot,
588 const XclAddress& rXclPos, sal_uInt16 nLastXclCol,
589 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId );
591 /** Tries to merge the contents of the passed cell to own data. */
592 virtual bool TryMerge( const XclExpCellBase& rCell );
593 /** Inserts the Excel XF index(es) into the passed vector. */
594 virtual void GetBlankXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
595 /** Tries to remove unused Excel XF index(es). */
596 virtual void RemoveUnusedBlankCells( const ScfUInt16Vec& rXFIndexes );
598 private:
599 /** Writes the remaining contents of the specified cell (without XF index). */
600 virtual void WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol );
601 virtual void WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol );
604 // ----------------------------------------------------------------------------
606 /** Represents an RK or MULRK record that describes cells with a compressed double values. */
607 class XclExpRkCell : public XclExpMultiCellBase
609 DECL_FIXEDMEMPOOL_NEWDEL( XclExpRkCell )
611 public:
612 explicit XclExpRkCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
613 const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
614 sal_Int32 nRkValue );
616 /** Tries to merge the contents of the passed cell to own data. */
617 virtual bool TryMerge( const XclExpCellBase& rCell );
619 private:
620 /** Writes the remaining contents of the specified cell (without XF index). */
621 virtual void WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol );
622 virtual void WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol );
624 private:
625 ScfInt32Vec maRkValues; /// The cell values.
628 // ============================================================================
629 // Rows and Columns
630 // ============================================================================
632 class ScOutlineArray;
634 /** Base class for buffers containing row or column outline data. */
635 class XclExpOutlineBuffer
637 public:
638 /** Returns true, if a collapsed group ends at the last processed position. */
639 inline bool IsCollapsed() const { return mbCurrCollapse; }
640 /** Returns the highest level of an open group at the last processed position. */
641 inline sal_uInt8 GetLevel() const { return ::std::min( mnCurrLevel, EXC_OUTLINE_MAX ); }
643 protected:
644 /** Constructs the outline buffer.
645 @param bRows true = Process row ouline array; false = Process column outline array. */
646 explicit XclExpOutlineBuffer( const XclExpRoot& rRoot, bool bRows );
648 /** Updates the current state by processing the settings at the passed Calc position. */
649 void UpdateColRow( SCCOLROW nScPos );
651 private:
652 /** Data about an outline level. */
653 struct XclExpLevelInfo
655 SCCOLROW mnScEndPos; /// The end position of a group in a level.
656 bool mbHidden; /// true = Group in this level is hidden.
657 inline explicit XclExpLevelInfo() : mnScEndPos( 0 ), mbHidden( false ) {}
659 typedef ::std::vector< XclExpLevelInfo > XclExpLevelInfoVec;
661 const ScOutlineArray* mpScOLArray; /// Pointer to Calc outline array.
662 XclExpLevelInfoVec maLevelInfos; /// Info for current row and all levels.
663 sal_uInt8 mnCurrLevel; /// Highest level of an open group for current position.
664 bool mbCurrCollapse; /// true = Collapsed group ends at current position.
667 // ----------------------------------------------------------------------------
669 /** The outline buffer for column outlines. */
670 class XclExpColOutlineBuffer : public XclExpOutlineBuffer
672 public:
673 inline explicit XclExpColOutlineBuffer( const XclExpRoot& rRoot ) :
674 XclExpOutlineBuffer( rRoot, false ) {}
676 /** Updates the current state by processing the settings of the passed Calc column. */
677 inline void Update( SCCOL nScCol )
678 { UpdateColRow( static_cast< SCCOLROW >( nScCol ) ); }
681 // ----------------------------------------------------------------------------
683 /** The outline buffer for row outlines. */
684 class XclExpRowOutlineBuffer : public XclExpOutlineBuffer
686 public:
687 inline explicit XclExpRowOutlineBuffer( const XclExpRoot& rRoot ) :
688 XclExpOutlineBuffer( rRoot, true ) {}
690 /** Updates the current state by processing the settings of the passed Calc row. */
691 inline void Update( SCROW nScRow )
692 { UpdateColRow( static_cast< SCCOLROW >( nScRow ) ); }
695 // ----------------------------------------------------------------------------
697 /** Represents a GUTS record containing the level count of row and column outlines. */
698 class XclExpGuts : public XclExpRecord
700 public:
701 explicit XclExpGuts( const XclExpRoot& rRoot );
703 private:
704 virtual void WriteBody( XclExpStream& rStrm );
706 private:
707 sal_uInt16 mnColLevels; /// Number of visible column outline levels.
708 sal_uInt16 mnColWidth; /// Width of column outline area (pixels).
709 sal_uInt16 mnRowLevels; /// Number of visible row outline levels.
710 sal_uInt16 mnRowWidth; /// Width of row outline area (pixels).
713 // ----------------------------------------------------------------------------
715 /** Represents a DIMENSIONS record containing the used area of a sheet. */
716 class XclExpDimensions : public XclExpRecord
718 public:
719 explicit XclExpDimensions( const XclExpRoot& rRoot );
721 /** Sets the used area to the record. */
722 void SetDimensions(
723 sal_uInt16 nFirstUsedXclCol, sal_uInt32 nFirstUsedXclRow,
724 sal_uInt16 nFirstFreeXclCol, sal_uInt32 nFirstFreeXclRow );
726 virtual void SaveXml( XclExpXmlStream& rStrm );
727 private:
728 /** Writes the contents of the DIMENSIONS record. */
729 virtual void WriteBody( XclExpStream& rStrm );
731 private:
732 sal_uInt32 mnFirstUsedXclRow; /// First used row.
733 sal_uInt32 mnFirstFreeXclRow; /// First unused row after used area.
734 sal_uInt16 mnFirstUsedXclCol; /// First used column.
735 sal_uInt16 mnFirstFreeXclCol; /// First free column after used area.
738 // ============================================================================
740 /** Represents the DEFCOLWIDTH record containing the default column width of a sheet.
742 Excel stores the default column width in entire character widths of the '0'
743 character using the application default font (i.e. the default width is 10,
744 if the '0' character fits 10 times into a cell in a column with default
745 width.
747 The IsDefWidth() function returns true, if the passed width (measured in
748 1/256 of the width of the '0' character) could be converted exactly to the
749 default width. If the passed width is rounded up or down to get the default
750 width, the function returns false.
752 class XclExpDefcolwidth : public XclExpUInt16Record, protected XclExpRoot
754 public:
755 explicit XclExpDefcolwidth( const XclExpRoot& rRoot );
757 /** Returns true, if the own default width exactly matches the passed width. */
758 bool IsDefWidth( sal_uInt16 nXclColWidth ) const;
760 /** Sets the passed column width (in 1/256 character width) as default width. */
761 void SetDefWidth( sal_uInt16 nXclColWidth );
764 // ----------------------------------------------------------------------------
766 /** Contains the column settings for a range of columns.
768 After construction the record contains a temporary XF identifier returned
769 from the XF buffer. After creating the entire Excel document in memory, the
770 ConvertXFIndexes() function converts it into the real Excel XF index.
772 class XclExpColinfo : public XclExpRecord, protected XclExpRoot
774 public:
775 /** Constructs the record with the settings in the Calc document. */
776 explicit XclExpColinfo( const XclExpRoot& rRoot,
777 SCCOL nScCol, SCROW nLastScRow,
778 XclExpColOutlineBuffer& rOutlineBfr );
780 /** Converts the XF identifier into the Excel XF index, returns the latter. */
781 sal_uInt16 ConvertXFIndexes();
783 /** Tries to merge this record with the passed record.
784 @descr Possible, if passed record directly follows this record and has equal contents.
785 @return true = This record is equal to passed record and has been updated. */
786 bool TryMerge( const XclExpColinfo& rColInfo );
788 /** Returns the Excel width of the column(s). */
789 inline sal_uInt16 GetColWidth() const { return mnWidth; }
790 /** Returns the final Excel XF index of the column(s). */
791 inline sal_uInt16 GetXFIndex() const { return maXFId.mnXFIndex; }
792 /** Returns the number of columns represented by this record. */
793 inline sal_uInt16 GetColCount() const { return mnLastXclCol - mnFirstXclCol + 1; }
795 /** Returns true, if the column has default format and width. */
796 bool IsDefault( const XclExpDefcolwidth& rDefColWidth ) const;
798 virtual void SaveXml( XclExpXmlStream& rStrm );
800 private:
801 /** Writes the contents of this COLINFO record. */
802 virtual void WriteBody( XclExpStream& rStrm );
804 private:
805 XclExpXFId maXFId; /// The XF identifier for column default format.
806 sal_uInt16 mnWidth; /// Excel width of the column.
807 sal_uInt16 mnFlags; /// Additional column flags.
808 sal_uInt16 mnFirstXclCol; /// Index to first column.
809 sal_uInt16 mnLastXclCol; /// Index to last column.
812 // ----------------------------------------------------------------------------
814 /** Contains COLINFO records for all columns of a Calc sheet.
816 On construction one COLINFO record per column is created. After creating
817 the entire Excel document in memory, the ConvertXFIndexes() function converts
818 all temporary XF identifiers into real Excel XF indexes and merges all equal
819 COLINFO records together.
821 class XclExpColinfoBuffer : public XclExpRecordBase, protected XclExpRoot
823 public:
824 explicit XclExpColinfoBuffer( const XclExpRoot& rRoot );
826 /** Initializes the buffer: finds settings and formatting of all columns.
827 @param nLastScRow Last row used to find default formatting. */
828 void Initialize( SCROW nLastScRow );
829 /** Converts the XF identifiers into the Excel XF indexes and merges equal columns.
830 @param rXFIndexes Returns the final XF indexes of all columns. */
831 void Finalize( ScfUInt16Vec& rXFIndexes );
833 /** Writes all COLINFO records of this buffer. */
834 virtual void Save( XclExpStream& rStrm );
835 virtual void SaveXml( XclExpXmlStream& rStrm );
837 private:
838 typedef XclExpRecordList< XclExpColinfo > XclExpColinfoList;
839 typedef XclExpColinfoList::RecordRefType XclExpColinfoRef;
841 XclExpColinfoList maColInfos; /// List of COLINFO records.
842 XclExpDefcolwidth maDefcolwidth; /// The DEFCOLWIDTH record.
843 XclExpColOutlineBuffer maOutlineBfr; /// Buffer for column outline groups.
846 // ============================================================================
848 class XclExpRow;
850 /** Contains all possible default row settings. */
851 struct XclExpDefaultRowData
853 sal_uInt16 mnFlags; /// Default flags for unspecified rows.
854 sal_uInt16 mnHeight; /// Default height for unspecified rows.
856 explicit XclExpDefaultRowData();
857 explicit XclExpDefaultRowData( const XclExpRow& rRow );
859 /** Returns true, if rows are hidden by default. */
860 inline bool IsHidden() const { return ::get_flag( mnFlags, EXC_DEFROW_HIDDEN ); }
861 /** Returns true, if the rows have a manually set height by default. */
862 inline bool IsUnsynced() const { return ::get_flag( mnFlags, EXC_DEFROW_UNSYNCED ); }
865 // ----------------------------------------------------------------------------
867 /** Represents a DEFROWHEIGHT record containing default format for unused rows. */
868 class XclExpDefrowheight : public XclExpRecord
870 public:
871 explicit XclExpDefrowheight();
873 /** Sets the passed default data as current record contents. */
874 void SetDefaultData( const XclExpDefaultRowData& rDefData );
876 private:
877 /** Writes the contents of the record. */
878 virtual void WriteBody( XclExpStream& rStrm );
880 private:
881 XclExpDefaultRowData maDefData; /// Record data.
884 // ----------------------------------------------------------------------------
886 /** Represents a ROW record and additionally contains all cells records of a row.
888 This class contains all cell records of a row in a spreadsheet. There are 2
889 cell records in Excel that support storing a range of cells in one record
890 (MULBLANK for multiple blank cells, and MULRK for multiple RK values). The
891 insertion functions try to merge a new inserted cell with existing
892 neighbors, if this is supported by the current type of cell record.
894 The Finalize() function converts the XF identifiers of all cell records to
895 the final Excel XF indexes. Then a default
897 class XclExpRow : public XclExpRecord, protected XclExpRoot
899 public:
900 /** Constructs the ROW record and converts the Calc row settings.
901 @param bAlwaysEmpty true = This row will not be filled with blank cells
902 in the Finalize() function. */
903 explicit XclExpRow( const XclExpRoot& rRoot, sal_uInt16 nXclRow,
904 XclExpRowOutlineBuffer& rOutlineBfr, bool bAlwaysEmpty );
906 /** Returns the excel row index of this ROW record. */
907 inline sal_uInt16 GetXclRow() const { return mnXclRow; }
908 /** Returns the height of the row in twips. */
909 inline sal_uInt16 GetHeight() const { return mnHeight; }
910 /** Returns true, if this row does not contain at least one valid cell. */
911 inline bool IsEmpty() const { return maCellList.IsEmpty(); }
912 /** Returns true, if this row is hidden. */
913 inline bool IsHidden() const { return ::get_flag( mnFlags, EXC_ROW_HIDDEN ); }
914 /** Returns true, if this row contains a manually set height. */
915 inline bool IsUnsynced() const { return ::get_flag( mnFlags, EXC_ROW_UNSYNCED ); }
916 /** Returns true, if this row is enabled (will be exported). */
917 inline bool IsEnabled() const { return mbEnabled; }
919 /** Appends the passed cell object to this row. */
920 void AppendCell( XclExpCellRef xCell, bool bIsMergedBase );
922 /** Converts all XF identifiers into the Excel XF indexes. */
923 void Finalize( const ScfUInt16Vec& rColXFIndexes );
925 /** Returns the column index of the first used cell in this row.
926 @descr This function can only be called after Finalize(). */
927 sal_uInt16 GetFirstUsedXclCol() const;
928 /** Returns the column index of the first unused cell following all used cells in this row.
929 @descr This function can only be called after Finalize(). */
930 sal_uInt16 GetFirstFreeXclCol() const;
932 /** Returns true, if this row may be omitted by using the DEFROWHEIGHT record.
933 @descr A row may be omitted, if it does not contain any cell or
934 explicit default cell formatting, and is not part of an outline.
935 This function can only be called after Finalize(). */
936 bool IsDefaultable() const;
937 /** Disables this row, if it is defaultable and has the passed default format.
938 @descr Disabled rows will not be saved.
939 This function can only be called after Finalize(). */
940 void DisableIfDefault( const XclExpDefaultRowData& rDefRowData );
942 /** Writes all cell records of this row. */
943 void WriteCellList( XclExpStream& rStrm );
945 /** Writes the ROW record if the row is not disabled (see DisableIfDefault() function). */
946 virtual void Save( XclExpStream& rStrm );
947 virtual void SaveXml( XclExpXmlStream& rStrm );
949 private:
950 /** Initializes the record data. Called from constructors. */
951 void Init( sal_uInt16 nXclRow, XclExpRowOutlineBuffer* pOutlineBfr );
952 /** Inserts a cell at the specified list position, tries to merge with neighbors. */
953 void InsertCell( XclExpCellRef xCell, size_t nPos, bool bIsMergedBase );
955 /** Writes the contents of the ROW record. */
956 virtual void WriteBody( XclExpStream& rStrm );
958 private:
959 typedef XclExpRecordList< XclExpCellBase > XclExpCellList;
961 XclExpCellList maCellList; /// List of cell records for this row.
962 sal_uInt16 mnXclRow; /// Excel row index of this row.
963 sal_uInt16 mnHeight; /// Row height in twips.
964 sal_uInt16 mnFlags; /// Flags for the ROW record.
965 sal_uInt16 mnXFIndex; /// Default row formatting.
966 sal_uInt16 mnOutlineLevel; /// Outline Level (for OOXML)
967 bool mbAlwaysEmpty; /// true = Do not add blank cells in Finalize().
968 bool mbEnabled; /// true = Write this ROW record.
971 // ----------------------------------------------------------------------------
973 /** Collects all rows which contain all cells of a sheet.
975 This row buffer automatically creates ROW records when cells are inserted
976 with the AppendCell() function. It is possible to force creation of more
977 ROW records with the CreateRows() function. In both cases, all preceding
978 missing ROW records are inserted too.
980 class XclExpRowBuffer : public XclExpRecordBase, protected XclExpRoot
982 public:
983 explicit XclExpRowBuffer( const XclExpRoot& rRoot );
985 /** Appends the passed cell object to the row that the cell specifies. */
986 void AppendCell( XclExpCellRef xCell, bool bIsMergedBase );
987 /** Forces insertion of all ROW records before the passed row. */
988 void CreateRows( SCROW nFirstFreeScRow );
990 /** Converts all XF identifiers into the Excel XF indexes and calculates default formats.
991 @param rDefRowData (out-param) The default row format is returned here.
992 @param rColXFIndexes The column default XF indexes. */
993 void Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt16Vec& rColXFIndexes );
995 /** Writes the DIMENSIONS record, all ROW records and all cell records. */
996 virtual void Save( XclExpStream& rStrm );
997 virtual void SaveXml( XclExpXmlStream& rStrm );
999 XclExpDimensions* GetDimensions();
1001 private:
1002 /** Returns access to the specified ROW record. Inserts preceding missing ROW records.
1003 @param bRowAlwaysEmpty true = Created rows will not be filled with blank cells
1004 in the XclExpRow::Finalize() function. */
1005 XclExpRow& GetOrCreateRow( sal_uInt16 nXclRow, bool bRowAlwaysEmpty );
1007 private:
1008 typedef XclExpRecordList< XclExpRow > XclExpRowList;
1009 typedef XclExpRowList::RecordRefType XclExpRowRef;
1011 XclExpRowList maRowList; /// List of all ROW records.
1012 XclExpRowOutlineBuffer maOutlineBfr; /// Buffer for row outline groups.
1013 XclExpDimensions maDimensions; /// DIMENSIONS record for used area.
1014 XclExpRow* mpLastUsedRow; /// Last used row for faster access.
1015 sal_uInt16 mnLastUsedXclRow; /// Last used row for faster access.
1018 // ============================================================================
1019 // Cell Table
1020 // ============================================================================
1022 class XclExpNote;
1023 class XclExpMergedcells;
1024 class XclExpHyperlink;
1025 class XclExpDval;
1027 /** This class contains the cell contents and more of an entire sheet.
1029 The cell table includes the settings and default formatting of all columns,
1030 the settings and default formatting of all used rows, and the contents of
1031 all cells of one sheet in a spreadsheet document.
1033 The constructor does all the work creating the cell table. It reads the
1034 Calc sheet and converts all columns, rows, and cells to Excel record data.
1035 Additioanlly, hyperlink records, note records, additional records for
1036 formula cells, data validation records, and outline records are created.
1038 The Finalize() function does even more work. It calculates default column
1039 settings and removes column records that are equal to this default. The
1040 same happens with rows: A default format is calculated for each row, and
1041 all blank cells in this row that have the same format are removed. Then,
1042 the most used row settings are calculated, and all empty rows that have the
1043 same settings are removed too.
1045 Records that are not stored inside the cell table area in an Excel file
1046 (i.e. DEFROWHEIGHT record, NOTE records, MERGEDCELLS record, HLINK records,
1047 DVAL and DV records for data validation) can be accessed with the function
1048 CreateRecord(). It returns the reference to the respective record (or
1049 record list) which can be inserted into a record list.
1051 class XclExpCellTable : public XclExpRecordBase, protected XclExpRoot
1053 public:
1054 explicit XclExpCellTable( const XclExpRoot& rRoot );
1056 /** Converts all XF identifiers into the Excel XF indexes and calculates default formats. */
1057 void Finalize();
1059 /** Returns the reference to an internal record specified by the passed record id.
1060 @param nRecId The record identifier that specifies which record is
1061 returned. Possible values are: EXC_ID_DEFROWHEIGHT, EXC_ID_NOTE,
1062 EXC_ID_MERGEDCELLS, EXC_ID_HLINK, EXC_ID_DVAL. */
1063 XclExpRecordRef CreateRecord( sal_uInt16 nRecId ) const;
1064 /** Saves the entire cell table. */
1065 virtual void Save( XclExpStream& rStrm );
1066 virtual void SaveXml( XclExpXmlStream& rStrm );
1068 private:
1069 typedef XclExpRecordList< XclExpNote > XclExpNoteList;
1070 typedef XclExpRecordList< XclExpHyperlink > XclExpHyperlinkList;
1072 typedef ScfRef< XclExpDefrowheight > XclExpDefrowhRef;
1073 typedef ScfRef< XclExpNoteList > XclExpNoteListRef;
1074 typedef ScfRef< XclExpMergedcells > XclExpMergedcellsRef;
1075 typedef ScfRef< XclExpHyperlinkList > XclExpHyperlinkRef;
1076 typedef ScfRef< XclExpDval > XclExpDvalRef;
1078 XclExpColinfoBuffer maColInfoBfr; /// Buffer for column formatting.
1079 XclExpRowBuffer maRowBfr; /// Rows and cell records.
1080 XclExpArrayBuffer maArrayBfr; /// Buffer for ARRAY records.
1081 XclExpShrfmlaBuffer maShrfmlaBfr; /// Buffer for SHRFMLA records.
1082 XclExpTableopBuffer maTableopBfr; /// Buffer for TABLEOP records.
1083 XclExpDefrowhRef mxDefrowheight; /// DEFROWHEIGHT record for default row format.
1084 XclExpRecordRef mxGuts; /// GUTS record for outline areas.
1085 XclExpNoteListRef mxNoteList; /// List of NOTE records.
1086 XclExpMergedcellsRef mxMergedcells; /// MERGEDCELLS record for merged cell ranges.
1087 XclExpHyperlinkRef mxHyperlinkList; /// List of HLINK records.
1088 XclExpDvalRef mxDval; /// Data validation with DVAL and DV records.
1091 #endif