Get the style color and number just once
[LibreOffice.git] / sc / source / filter / inc / sheetdatabuffer.hxx
blob5386313300820f60ac1cc14662e804dad6849f27
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <vector>
23 #include <map>
24 #include <o3tl/sorted_vector.hxx>
26 #include "richstring.hxx"
27 #include "worksheethelper.hxx"
28 #include "addressconverter.hxx"
30 namespace com::sun::star {
31 namespace util { struct DateTime; }
34 namespace oox::xls {
36 /** Stores basic data about cell values and formatting. */
37 struct CellModel
39 ScAddress maCellAddr; /// The address of the current cell.
40 sal_Int32 mnCellType; /// Data type of the cell value.
41 sal_Int32 mnXfId; /// XF (cell formatting) identifier.
42 bool mbShowPhonetic; /// True = show phonetic text.
44 explicit CellModel();
47 /** Stores data about cell formulas. */
48 struct CellFormulaModel
50 ScRange maFormulaRef; /// Formula range for array/shared formulas and data tables.
51 sal_Int32 mnFormulaType; /// Type of the formula (regular, array, shared, table).
52 sal_Int32 mnSharedId; /// Identifier of a shared formula (OOXML only).
54 explicit CellFormulaModel();
56 /** Returns true, if the passed cell address is valid for an array formula. */
57 bool isValidArrayRef( const ScAddress& rCellAddr );
58 /** Returns true, if the passed cell address is valid for a shared formula. */
59 bool isValidSharedRef( const ScAddress& rCellAddr );
62 /** Stores data about table operations. */
63 struct DataTableModel
65 OUString maRef1; /// First reference cell for table operations.
66 OUString maRef2; /// Second reference cell for table operations.
67 bool mb2dTable; /// True = 2-dimensional data table.
68 bool mbRowTable; /// True = row oriented data table.
69 bool mbRef1Deleted; /// True = first reference cell deleted.
70 bool mbRef2Deleted; /// True = second reference cell deleted.
72 explicit DataTableModel();
75 /** Manages the cell contents and cell formatting of a sheet.
77 class SheetDataBuffer : public WorksheetHelper
79 public:
80 explicit SheetDataBuffer( const WorksheetHelper& rHelper );
82 /** Inserts a blank cell (with formatting) into the sheet. */
83 void setBlankCell( const CellModel& rModel );
84 /** Inserts a value cell into the sheet. */
85 void setValueCell( const CellModel& rModel, double fValue );
86 /** Inserts a simple string cell into the sheet. */
87 void setStringCell( const CellModel& rModel, const OUString& rText );
88 /** Inserts a rich-string cell into the sheet. */
89 void setStringCell( const CellModel& rModel, const RichStringRef& rxString );
90 /** Inserts a shared string cell into the sheet. */
91 void setStringCell( const CellModel& rModel, sal_Int32 nStringId );
92 /** Inserts a date/time cell into the sheet and adjusts number format. */
93 void setDateTimeCell( const CellModel& rModel, const css::util::DateTime& rDateTime );
94 /** Inserts a boolean cell into the sheet and adjusts number format. */
95 void setBooleanCell( const CellModel& rModel, bool bValue );
96 /** Inserts an error cell from the passed error code into the sheet. */
97 void setErrorCell( const CellModel& rModel, const OUString& rErrorCode );
98 /** Inserts an error cell from the passed BIFF error code into the sheet. */
99 void setErrorCell( const CellModel& rModel, sal_uInt8 nErrorCode );
100 /** Inserts a formula cell into the sheet. */
101 void setFormulaCell( const CellModel& rModel, const ApiTokenSequence& rTokens );
102 /** Inserts an ISO 8601 date cell into the sheet. */
103 void setDateCell( const CellModel& rModel, const OUString& rDateString );
105 void createSharedFormula(
106 const ScAddress& rRange,
107 const ApiTokenSequence& rTokens);
109 /** Inserts the passed token array as array formula. */
110 void createArrayFormula(
111 const ScRange& rRange,
112 const ApiTokenSequence& rTokens );
113 /** Sets a multiple table operation to the passed range. */
114 void createTableOperation(
115 const ScRange& rRange,
116 const DataTableModel& rModel );
118 /** Sets default cell formatting for the specified range of rows. */
119 void setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat );
120 /** Merges the cells in the passed cell range. */
121 void setMergedRange( const ScRange& rRange );
123 /** Processes the cell formatting data of the passed cell. */
124 void setCellFormat( const CellModel& rModel );
126 /** Final processing after the sheet has been imported. */
127 void finalizeImport();
129 /** Sets the passed formula token array into a cell. */
130 void setCellFormula(
131 const ScAddress& rCellAddr,
132 const ApiTokenSequence& rTokens );
133 private:
135 /** Creates a formula token array representing the shared formula with the
136 passed identifier. */
137 ApiTokenSequence resolveSharedFormula( const ScAddress& rMapKey ) const;
139 /** Inserts the passed array formula into the sheet. */
140 void finalizeArrayFormula(
141 const ScRange& rRange,
142 const ApiTokenSequence& rTokens ) const;
143 /** Inserts the passed table operation into the sheet. */
144 void finalizeTableOperation(
145 const ScRange& rRange, const DataTableModel& rModel );
147 /** Writes all cell formatting attributes to the passed cell range list. (depreciates writeXfIdRangeProperties) */
148 void applyCellMerging( const ScRange& rRange );
149 void addColXfStyles();
150 void addColXfStyleProcessRowRanges();
151 private:
152 /** Stores cell range address and formula token array of an array formula. */
153 typedef std::pair< ScRange, ApiTokenSequence > ArrayFormula;
154 typedef ::std::vector< ArrayFormula > ArrayFormulaVector;
156 /** Stores cell range address and settings of a table operation. */
157 typedef std::pair< ScRange, DataTableModel > TableOperation;
159 /** Stores information about a range of rows with equal cell formatting. */
160 struct XfIdRowRange
162 ValueRange maRowRange; /// Indexes of first and last row.
163 sal_Int32 mnXfId; /// XF identifier for the row range.
165 explicit XfIdRowRange();
166 void set( sal_Int32 nRow, sal_Int32 nXfId );
167 bool tryExpand( sal_Int32 nRow, sal_Int32 nXfId );
170 typedef ::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey;
172 struct RowRangeStyle
174 sal_Int32 mnStartRow;
175 sal_Int32 mnEndRow;
176 XfIdNumFmtKey mnNumFmt;
178 struct StyleRowRangeComp
180 bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
182 // This end-vs-start comparison is needed by the lower_bound() use
183 // in SheetDataBuffer::addColXfStyleProcessRowRanges() that searches
184 // for partially overlapping ranges. In all other places the ranges
185 // should be non-overlapping, in which case this is the same as the "normal"
186 // comparison.
187 return lhs.mnEndRow<rhs.mnStartRow;
190 typedef ::o3tl::sorted_vector< RowRangeStyle, StyleRowRangeComp > RowStyles;
191 typedef ::std::map< sal_Int32, RowStyles > ColStyles;
192 typedef ::std::vector< RowRangeStyle > TmpRowStyles;
193 typedef ::std::map< sal_Int32, TmpRowStyles > TmpColStyles;
194 /** Stores information about a merged cell range. */
195 struct MergedRange
197 ScRange maRange; /// The formatted cell range.
198 sal_Int32 mnHorAlign; /// Horizontal alignment in the range.
200 explicit MergedRange( const ScRange& rRange );
201 explicit MergedRange( const ScAddress& rAddress, sal_Int32 nHorAlign );
202 bool tryExpand( const ScAddress& rAddress, sal_Int32 nHorAlign );
204 typedef ::std::vector< MergedRange > MergedRangeVector;
206 ColStyles maStylesPerColumn; /// Stores cell styles by column ( in row ranges )
207 ArrayFormulaVector maArrayFormulas; /// All array formulas in the sheet.
208 std::vector< TableOperation >
209 maTableOperations; /// All table operations in the sheet.
210 ::std::map< BinAddress, ApiTokenSequence >
211 maSharedFormulas; /// Maps shared formula base address to defined name token index.
212 ScAddress maSharedFmlaAddr; /// Address of a cell containing a pending shared formula.
213 ScAddress maSharedBaseAddr; /// Base address of the pending shared formula.
214 XfIdRowRange maXfIdRowRange; /// Cached XF identifier for a range of rows.
215 std::map< XfIdNumFmtKey, ScRangeList >
216 maXfIdRangeLists; /// Collected XF identifiers for cell rangelists.
217 MergedRangeVector maMergedRanges; /// Merged cell ranges.
218 MergedRangeVector maCenterFillRanges; /// Merged cell ranges from 'center across' or 'fill' alignment.
219 bool mbPendingSharedFmla; /// True = maSharedFmlaAddr and maSharedBaseAddr are valid.
220 std::map< sal_Int32, std::vector< ValueRange > > maXfIdRowRangeList; /// Cached XF identifiers for a ranges of rows, we try and process rowranges with the same XF id together
223 } // namespace oox::xls
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */