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