LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / source / filter / inc / sheetdatabuffer.hxx
blobac095cccdd263c9eb69a542e98da20ab8a8c366e
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 <set>
25 #include <o3tl/sorted_vector.hxx>
27 #include "richstring.hxx"
28 #include "worksheethelper.hxx"
29 #include "addressconverter.hxx"
31 namespace com::sun::star {
32 namespace util { struct DateTime; }
35 namespace oox::xls {
37 /** Stores basic data about cell values and formatting. */
38 struct CellModel
40 ScAddress maCellAddr; /// The address of the current cell.
41 sal_Int32 mnCellType; /// Data type of the cell value.
42 sal_Int32 mnXfId; /// XF (cell formatting) identifier.
43 bool mbShowPhonetic; /// True = show phonetic text.
45 explicit CellModel();
48 /** Stores data about cell formulas. */
49 struct CellFormulaModel
51 ScRange maFormulaRef; /// Formula range for array/shared formulas and data tables.
52 sal_Int32 mnFormulaType; /// Type of the formula (regular, array, shared, table).
53 sal_Int32 mnSharedId; /// Identifier of a shared formula (OOXML only).
55 explicit CellFormulaModel();
57 /** Returns true, if the passed cell address is valid for an array formula. */
58 bool isValidArrayRef( const ScAddress& rCellAddr );
59 /** Returns true, if the passed cell address is valid for a shared formula. */
60 bool isValidSharedRef( const ScAddress& rCellAddr );
63 /** Stores data about table operations. */
64 struct DataTableModel
66 OUString maRef1; /// First reference cell for table operations.
67 OUString maRef2; /// Second reference cell for table operations.
68 bool mb2dTable; /// True = 2-dimensional data table.
69 bool mbRowTable; /// True = row oriented data table.
70 bool mbRef1Deleted; /// True = first reference cell deleted.
71 bool mbRef2Deleted; /// True = second reference cell deleted.
73 explicit DataTableModel();
76 /** Manages the cell contents and cell formatting of a sheet.
78 class SheetDataBuffer : public WorksheetHelper
80 public:
81 explicit SheetDataBuffer( const WorksheetHelper& rHelper );
83 /** Inserts a blank cell (with formatting) into the sheet. */
84 void setBlankCell( const CellModel& rModel );
85 /** Inserts a value cell into the sheet. */
86 void setValueCell( const CellModel& rModel, double fValue );
87 /** Inserts a simple string cell into the sheet. */
88 void setStringCell( const CellModel& rModel, const OUString& rText );
89 /** Inserts a rich-string cell into the sheet. */
90 void setStringCell( const CellModel& rModel, const RichStringRef& rxString );
91 /** Inserts a shared string cell into the sheet. */
92 void setStringCell( const CellModel& rModel, sal_Int32 nStringId );
93 /** Inserts a date/time cell into the sheet and adjusts number format. */
94 void setDateTimeCell( const CellModel& rModel, const css::util::DateTime& rDateTime );
95 /** Inserts a boolean cell into the sheet and adjusts number format. */
96 void setBooleanCell( const CellModel& rModel, bool bValue );
97 /** Inserts an error cell from the passed error code into the sheet. */
98 void setErrorCell( const CellModel& rModel, const OUString& rErrorCode );
99 /** Inserts an error cell from the passed BIFF error code into the sheet. */
100 void setErrorCell( const CellModel& rModel, sal_uInt8 nErrorCode );
101 /** Inserts a formula cell into the sheet. */
102 void setFormulaCell( const CellModel& rModel, const ApiTokenSequence& rTokens );
103 /** Inserts an ISO 8601 date cell into the sheet. */
104 void setDateCell( const CellModel& rModel, const OUString& rDateString );
106 void createSharedFormula(
107 const ScAddress& rRange,
108 const ApiTokenSequence& rTokens);
110 /** Inserts the passed token array as array formula. */
111 void createArrayFormula(
112 const ScRange& rRange,
113 const ApiTokenSequence& rTokens );
114 /** Sets a multiple table operation to the passed range. */
115 void createTableOperation(
116 const ScRange& rRange,
117 const DataTableModel& rModel );
119 /** Sets default cell formatting for the specified range of rows. */
120 void setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat );
121 /** Merges the cells in the passed cell range. */
122 void setMergedRange( const ScRange& rRange );
124 /** Processes the cell formatting data of the passed cell. */
125 void setCellFormat( const CellModel& rModel );
127 /** Final processing after the sheet has been imported. */
128 void finalizeImport();
130 /** Sets the passed formula token array into a cell. */
131 void setCellFormula(
132 const ScAddress& rCellAddr,
133 const ApiTokenSequence& rTokens );
134 private:
136 /** Creates a formula token array representing the shared formula with the
137 passed identifier. */
138 ApiTokenSequence resolveSharedFormula( const ScAddress& rMapKey ) const;
140 /** Inserts the passed array formula into the sheet. */
141 void finalizeArrayFormula(
142 const ScRange& rRange,
143 const ApiTokenSequence& rTokens ) const;
144 /** Inserts the passed table operation into the sheet. */
145 void finalizeTableOperation(
146 const ScRange& rRange, const DataTableModel& rModel );
148 /** Writes all cell formatting attributes to the passed cell range list. (depreciates writeXfIdRangeProperties) */
149 void applyCellMerging( const ScRange& rRange );
150 void addColXfStyles();
151 void addColXfStyleProcessRowRanges();
152 private:
153 /** Stores cell range address and formula token array of an array formula. */
154 typedef std::pair< ScRange, ApiTokenSequence > ArrayFormula;
155 typedef ::std::vector< ArrayFormula > ArrayFormulaVector;
157 /** Stores cell range address and settings of a table operation. */
158 typedef std::pair< ScRange, DataTableModel > TableOperation;
160 /** Stores information about a range of rows with equal cell formatting. */
161 struct XfIdRowRange
163 ValueRange maRowRange; /// Indexes of first and last row.
164 sal_Int32 mnXfId; /// XF identifier for the row range.
166 explicit XfIdRowRange();
167 void set( sal_Int32 nRow, sal_Int32 nXfId );
168 bool tryExpand( sal_Int32 nRow, sal_Int32 nXfId );
171 typedef ::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey;
173 struct RowRangeStyle
175 sal_Int32 mnStartRow;
176 sal_Int32 mnEndRow;
177 XfIdNumFmtKey mnNumFmt;
179 struct StyleRowRangeComp
181 bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
183 // This end-vs-start comparison is needed by the lower_bound() use
184 // in SheetDataBuffer::addColXfStyleProcessRowRanges() that searches
185 // for partially overlapping ranges. In all other places the ranges
186 // should be non-overlapping, in which case this is the same as the "normal"
187 // comparison.
188 return lhs.mnEndRow<rhs.mnStartRow;
191 typedef ::o3tl::sorted_vector< RowRangeStyle, StyleRowRangeComp > RowStyles;
192 typedef ::std::map< sal_Int32, RowStyles > ColStyles;
193 typedef ::std::vector< RowRangeStyle > TmpRowStyles;
194 typedef ::std::map< sal_Int32, TmpRowStyles > TmpColStyles;
195 /** Stores information about a merged cell range. */
196 struct MergedRange
198 ScRange maRange; /// The formatted cell range.
199 sal_Int32 mnHorAlign; /// Horizontal alignment in the range.
201 explicit MergedRange( const ScRange& rRange );
202 explicit MergedRange( const ScAddress& rAddress, sal_Int32 nHorAlign );
203 bool tryExpand( const ScAddress& rAddress, sal_Int32 nHorAlign );
205 typedef ::std::vector< MergedRange > MergedRangeVector;
207 ColStyles maStylesPerColumn; /// Stores cell styles by column ( in row ranges )
208 ArrayFormulaVector maArrayFormulas; /// All array formulas in the sheet.
209 std::vector< TableOperation >
210 maTableOperations; /// All table operations in the sheet.
211 ::std::map< BinAddress, ApiTokenSequence >
212 maSharedFormulas; /// Maps shared formula base address to defined name token index.
213 ScAddress maSharedFmlaAddr; /// Address of a cell containing a pending shared formula.
214 ScAddress maSharedBaseAddr; /// Base address of the pending shared formula.
215 XfIdRowRange maXfIdRowRange; /// Cached XF identifier for a range of rows.
216 std::map< XfIdNumFmtKey, ScRangeList >
217 maXfIdRangeLists; /// Collected XF identifiers for cell rangelists.
218 MergedRangeVector maMergedRanges; /// Merged cell ranges.
219 MergedRangeVector maCenterFillRanges; /// Merged cell ranges from 'center across' or 'fill' alignment.
220 bool mbPendingSharedFmla; /// True = maSharedFmlaAddr and maSharedBaseAddr are valid.
221 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
224 } // namespace oox::xls
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */