Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef OOX_XLS_SHEETDATABUFFER_HXX
21 : #define OOX_XLS_SHEETDATABUFFER_HXX
22 :
23 : #include <list>
24 : #include <map>
25 : #include "richstring.hxx"
26 : #include "worksheethelper.hxx"
27 :
28 : namespace com { namespace sun { namespace star {
29 : namespace util { struct DateTime; }
30 : } } }
31 :
32 : namespace oox {
33 : namespace xls {
34 :
35 : // ============================================================================
36 :
37 : /** Stores basic data about cell values and formatting. */
38 : struct CellModel
39 : {
40 : ::com::sun::star::table::CellAddress
41 : maCellAddr; /// The address of the current cell.
42 : sal_Int32 mnCellType; /// Data type of the cell value.
43 : sal_Int32 mnXfId; /// XF (cell formatting) identifier.
44 : bool mbShowPhonetic; /// True = show phonetic text.
45 :
46 : explicit CellModel();
47 : };
48 :
49 : // ----------------------------------------------------------------------------
50 :
51 : /** Stores data about cell formulas. */
52 : struct CellFormulaModel
53 : {
54 : ::com::sun::star::table::CellRangeAddress
55 : maFormulaRef; /// Formula range for array/shared formulas and data tables.
56 : sal_Int32 mnFormulaType; /// Type of the formula (regular, array, shared, table).
57 : sal_Int32 mnSharedId; /// Identifier of a shared formula (OOXML only).
58 :
59 : explicit CellFormulaModel();
60 :
61 : /** Returns true, if the passed cell address is valid for an array formula. */
62 : bool isValidArrayRef( const ::com::sun::star::table::CellAddress& rCellAddr );
63 : /** Returns true, if the passed cell address is valid for a shared formula. */
64 : bool isValidSharedRef( const ::com::sun::star::table::CellAddress& rCellAddr );
65 : };
66 :
67 : // ----------------------------------------------------------------------------
68 :
69 : /** Stores data about table operations. */
70 25 : struct DataTableModel
71 : {
72 : ::rtl::OUString maRef1; /// First reference cell for table operations.
73 : ::rtl::OUString maRef2; /// Second reference cell for table operations.
74 : bool mb2dTable; /// True = 2-dimensional data table.
75 : bool mbRowTable; /// True = row oriented data table.
76 : bool mbRef1Deleted; /// True = first reference cell deleted.
77 : bool mbRef2Deleted; /// True = second reference cell deleted.
78 :
79 : explicit DataTableModel();
80 : };
81 :
82 : // ============================================================================
83 :
84 : /** Manages all cell blocks currently in use. */
85 25 : class CellBlockBuffer : public WorksheetHelper
86 : {
87 : public:
88 : explicit CellBlockBuffer( const WorksheetHelper& rHelper );
89 :
90 : /** Sets column span information for a row. */
91 : void setColSpans( sal_Int32 nRow, const ValueRangeSet& rColSpans );
92 :
93 : /** Inserts all cells of all open cell blocks into the Calc document. */
94 : void finalizeImport();
95 :
96 : private:
97 : typedef ::std::map< sal_Int32, ValueRangeVector > ColSpanVectorMap;
98 :
99 : ColSpanVectorMap maColSpans; /// Buffereed column spans, mapped by row index.
100 : sal_Int32 mnCurrRow; /// Current row index used for buffered cell import.
101 : };
102 :
103 : // ============================================================================
104 :
105 :
106 : /** Manages the cell contents and cell formatting of a sheet.
107 : */
108 25 : class SheetDataBuffer : public WorksheetHelper
109 : {
110 : public:
111 : explicit SheetDataBuffer( const WorksheetHelper& rHelper );
112 :
113 : /** Sets column span information for a row. */
114 : void setColSpans( sal_Int32 nRow, const ValueRangeSet& rColSpans );
115 :
116 : /** Inserts a blank cell (with formatting) into the sheet. */
117 : void setBlankCell( const CellModel& rModel );
118 : /** Inserts a value cell into the sheet. */
119 : void setValueCell( const CellModel& rModel, double fValue );
120 : /** Inserts a simple string cell into the sheet. */
121 : void setStringCell( const CellModel& rModel, const ::rtl::OUString& rText );
122 : /** Inserts a rich-string cell into the sheet. */
123 : void setStringCell( const CellModel& rModel, const RichStringRef& rxString );
124 : /** Inserts a shared string cell into the sheet. */
125 : void setStringCell( const CellModel& rModel, sal_Int32 nStringId );
126 : /** Inserts a date/time cell into the sheet and adjusts number format. */
127 : void setDateTimeCell( const CellModel& rModel, const ::com::sun::star::util::DateTime& rDateTime );
128 : /** Inserts a boolean cell into the sheet and adjusts number format. */
129 : void setBooleanCell( const CellModel& rModel, bool bValue );
130 : /** Inserts an error cell from the passed error code into the sheet. */
131 : void setErrorCell( const CellModel& rModel, const ::rtl::OUString& rErrorCode );
132 : /** Inserts an error cell from the passed BIFF error code into the sheet. */
133 : void setErrorCell( const CellModel& rModel, sal_uInt8 nErrorCode );
134 : /** Inserts a formula cell into the sheet. */
135 : void setFormulaCell( const CellModel& rModel, const ApiTokenSequence& rTokens );
136 :
137 : /** Inserts the passed token array as array formula. */
138 : void createArrayFormula(
139 : const ::com::sun::star::table::CellRangeAddress& rRange,
140 : const ApiTokenSequence& rTokens );
141 : /** Sets a multiple table operation to the passed range. */
142 : void createTableOperation(
143 : const ::com::sun::star::table::CellRangeAddress& rRange,
144 : const DataTableModel& rModel );
145 :
146 : /** Creates a named range with a special name for a shared formula with the
147 : specified base address and formula definition (BIFF only). */
148 : void createSharedFormula(
149 : const ::com::sun::star::table::CellAddress& rCellAddr,
150 : const ApiTokenSequence& rTokens );
151 :
152 : /** Sets default cell formatting for the specified range of rows. */
153 : void setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat );
154 : /** Merges the cells in the passed cell range. */
155 : void setMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange );
156 : /** Sets a standard number format (constant from com.sun.star.util.NumberFormat) to the specified cell. */
157 : void setStandardNumFmt(
158 : const ::com::sun::star::table::CellAddress& rCellAddr,
159 : sal_Int16 nStdNumFmt );
160 : /** Processes the cell formatting data of the passed cell.
161 : @param nNumFmtId If set, overrides number format of the cell XF. */
162 : void setCellFormat( const CellModel& rModel, sal_Int32 nNumFmtId = -1 );
163 :
164 :
165 : /** Final processing after the sheet has been imported. */
166 : void finalizeImport();
167 :
168 : private:
169 : struct XfIdRowRange;
170 :
171 : /** Sets the passed formula token array into a cell. */
172 : void setCellFormula(
173 : const ::com::sun::star::table::CellAddress& rCellAddr,
174 : const ApiTokenSequence& rTokens );
175 :
176 : /** Creates a named range with a special name for a shared formula with the
177 : specified base address and formula definition. */
178 : void createSharedFormula( const BinAddress& rMapKey, const ApiTokenSequence& rTokens );
179 : /** Creates a formula token array representing the shared formula with the
180 : passed identifier. */
181 : ApiTokenSequence resolveSharedFormula( const BinAddress& rMapKey ) const;
182 :
183 : /** Inserts the passed array formula into the sheet. */
184 : void finalizeArrayFormula(
185 : const ::com::sun::star::table::CellRangeAddress& rRange,
186 : const ApiTokenSequence& rTokens ) const;
187 : /** Inserts the passed table operation into the sheet. */
188 : void finalizeTableOperation(
189 : const ::com::sun::star::table::CellRangeAddress& rRange,
190 : const DataTableModel& rModel ) const;
191 :
192 : /** Writes all cell formatting attributes to the passed cell range list. (depreciates writeXfIdRangeProperties) */
193 : void writeXfIdRangeListProperties( sal_Int32 nXfId, sal_Int32 nNumFmtId, const ApiCellRangeList& rRanges ) const;
194 : void applyCellMerging( const ::com::sun::star::table::CellRangeAddress& rRange );
195 :
196 : private:
197 : /** Stores cell range address and formula token array of an array formula. */
198 : typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, ApiTokenSequence > ArrayFormula;
199 : typedef ::std::list< ArrayFormula > ArrayFormulaList;
200 :
201 : /** Stores cell range address and settings of a table operation. */
202 : typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, DataTableModel > TableOperation;
203 : typedef ::std::list< TableOperation > TableOperationList;
204 :
205 :
206 : /** Stores information about a range of rows with equal cell formatting. */
207 : struct XfIdRowRange
208 : {
209 : ValueRange maRowRange; /// Indexes of first and last row.
210 : sal_Int32 mnXfId; /// XF identifier for the row range.
211 :
212 : explicit XfIdRowRange();
213 : void set( sal_Int32 nRow, sal_Int32 nXfId );
214 : bool tryExpand( sal_Int32 nRow, sal_Int32 nXfId );
215 : };
216 :
217 : typedef ::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey;
218 : typedef ::std::map< XfIdNumFmtKey, ApiCellRangeList > XfIdRangeListMap;
219 :
220 : /** Stores information about a merged cell range. */
221 : struct MergedRange
222 : {
223 : ::com::sun::star::table::CellRangeAddress
224 : maRange; /// The formatted cell range.
225 : sal_Int32 mnHorAlign; /// Horizontal alignment in the range.
226 :
227 : explicit MergedRange( const ::com::sun::star::table::CellRangeAddress& rRange );
228 : explicit MergedRange( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nHorAlign );
229 : bool tryExpand( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nHorAlign );
230 : };
231 : typedef ::std::list< MergedRange > MergedRangeList;
232 :
233 : CellBlockBuffer maCellBlocks; /// Manages all open cell blocks.
234 : ArrayFormulaList maArrayFormulas; /// All array formulas in the sheet.
235 : TableOperationList maTableOperations; /// All table operations in the sheet.
236 : SharedFormulaMap maSharedFormulas; /// Maps shared formula base address to defined name token index.
237 : ::com::sun::star::table::CellAddress
238 : maSharedFmlaAddr; /// Address of a cell containing a pending shared formula.
239 : BinAddress maSharedBaseAddr; /// Base address of the pending shared formula.
240 : XfIdRowRange maXfIdRowRange; /// Cached XF identifier for a range of rows.
241 : XfIdRangeListMap maXfIdRangeLists; /// Collected XF identifiers for cell rangelists.
242 : MergedRangeList maMergedRanges; /// Merged cell ranges.
243 : MergedRangeList maCenterFillRanges; /// Merged cell ranges from 'center across' or 'fill' alignment.
244 : bool mbPendingSharedFmla; /// True = maSharedFmlaAddr and maSharedBaseAddr are valid.
245 : 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
246 : };
247 :
248 : // ============================================================================
249 :
250 : } // namespace xls
251 : } // namespace oox
252 :
253 : #endif
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|