Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / inc / dociter.hxx
blobb73d175a000f8555b5dfee6b9804b68bc14f91dc
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 "address.hxx"
23 #include "formulagroup.hxx"
24 #include "global.hxx"
25 #include "scdllapi.h"
26 #include "cellvalue.hxx"
27 #include "mtvelements.hxx"
28 #include "queryparam.hxx"
29 #include <vcl/outdev.hxx>
30 #include <vcl/vclptr.hxx>
32 #include <memory>
33 #include <set>
34 #include <vector>
36 class ScDocument;
37 class ScPatternAttr;
38 class ScAttrArray;
39 class ScAttrIterator;
40 class ScFlatBoolRowSegments;
41 class ScMatrix;
42 struct ScDBQueryParamBase;
43 struct ScQueryParam;
44 struct ScDBQueryParamInternal;
45 struct ScDBQueryParamMatrix;
46 class ScFormulaCell;
47 class OutputDevice;
48 struct ScInterpreterContext;
49 enum class SvNumFormatType : sal_Int16;
51 class ScValueIterator // walk through all values in an area
53 typedef sc::CellStoreType::const_position_type PositionType;
55 const ScDocument& mrDoc;
56 ScInterpreterContext& mrContext;
57 const ScAttrArray* pAttrArray;
58 sal_uInt32 nNumFormat; // for CalcAsShown
59 sal_uInt32 nNumFmtIndex;
60 ScAddress maStartPos;
61 ScAddress maEndPos;
62 SCCOL mnCol;
63 SCTAB mnTab;
64 SCROW nAttrEndRow;
65 SubtotalFlags mnSubTotalFlags;
66 SvNumFormatType nNumFmtType;
67 bool bNumValid;
68 bool bCalcAsShown;
69 bool bTextAsZero;
71 const sc::CellStoreType* mpCells;
72 PositionType maCurPos;
74 SCROW GetRow() const;
75 void IncBlock();
76 void IncPos();
78 /**
79 * See if the cell at the current position is a non-empty cell. If not,
80 * move to the next non-empty cell position.
82 bool GetThis( double& rValue, FormulaError& rErr );
84 public:
86 ScValueIterator(ScInterpreterContext& rContext,
87 const ScRange& rRange, SubtotalFlags nSubTotalFlags = SubtotalFlags::NONE,
88 bool bTextAsZero = false );
90 void GetCurNumFmtInfo( SvNumFormatType& nType, sal_uInt32& nIndex );
92 /// Does NOT reset rValue if no value found!
93 bool GetFirst( double& rValue, FormulaError& rErr );
95 /// Does NOT reset rValue if no value found!
96 bool GetNext( double& rValue, FormulaError& rErr );
99 class ScDBQueryDataIterator
101 public:
102 struct Value
104 OUString maString;
105 double mfValue;
106 FormulaError mnError;
107 bool mbIsNumber;
109 Value();
112 private:
113 static const sc::CellStoreType* GetColumnCellStore(ScDocument& rDoc, SCTAB nTab, SCCOL nCol);
114 static const ScAttrArray* GetAttrArrayByCol(ScDocument& rDoc, SCTAB nTab, SCCOL nCol);
115 static bool IsQueryValid(ScDocument& rDoc, const ScQueryParam& rParam, SCTAB nTab, SCROW nRow, const ScRefCellValue* pCell);
117 class DataAccess
119 public:
120 DataAccess();
121 virtual ~DataAccess() = 0;
122 virtual bool getCurrent(Value& rValue) = 0;
123 virtual bool getFirst(Value& rValue) = 0;
124 virtual bool getNext(Value& rValue) = 0;
127 class DataAccessInternal final : public DataAccess
129 typedef std::pair<sc::CellStoreType::const_iterator,size_t> PositionType;
130 public:
131 DataAccessInternal(ScDBQueryParamInternal* pParam, ScDocument& rDoc, const ScInterpreterContext& rContext);
132 virtual ~DataAccessInternal() override;
133 virtual bool getCurrent(Value& rValue) override;
134 virtual bool getFirst(Value& rValue) override;
135 virtual bool getNext(Value& rValue) override;
137 private:
138 void incBlock();
139 void incPos();
141 const sc::CellStoreType* mpCells;
142 PositionType maCurPos;
143 ScDBQueryParamInternal* mpParam;
144 ScDocument& mrDoc;
145 const ScInterpreterContext& mrContext;
146 const ScAttrArray* pAttrArray;
147 sal_uInt32 nNumFormat; // for CalcAsShown
148 sal_uInt32 nNumFmtIndex;
149 SCCOL nCol;
150 SCROW nRow;
151 SCROW nAttrEndRow;
152 SCTAB nTab;
153 SvNumFormatType nNumFmtType;
154 bool bCalcAsShown;
157 class DataAccessMatrix final : public DataAccess
159 public:
160 DataAccessMatrix(ScDBQueryParamMatrix* pParam);
161 virtual ~DataAccessMatrix() override;
162 virtual bool getCurrent(Value& rValue) override;
163 virtual bool getFirst(Value& rValue) override;
164 virtual bool getNext(Value& rValue) override;
166 private:
167 bool isValidQuery(SCROW mnRow, const ScMatrix& rMat) const;
169 ScDBQueryParamMatrix* mpParam;
170 SCROW mnCurRow;
171 SCROW mnRows;
174 ::std::unique_ptr<ScDBQueryParamBase> mpParam;
175 ::std::unique_ptr<DataAccess> mpData;
177 public:
178 ScDBQueryDataIterator(ScDocument& rDocument, const ScInterpreterContext& rContext, std::unique_ptr<ScDBQueryParamBase> pParam);
179 /// Does NOT reset rValue if no value found!
180 bool GetFirst(Value& rValue);
181 /// Does NOT reset rValue if no value found!
182 bool GetNext(Value& rValue);
185 class ScFormulaGroupIterator
187 private:
188 ScDocument& mrDoc;
189 SCTAB mnTab;
190 SCCOL mnCol;
191 bool mbNullCol;
192 size_t mnIndex;
193 std::vector<sc::FormulaGroupEntry> maEntries;
195 public:
196 ScFormulaGroupIterator( ScDocument& rDoc );
198 sc::FormulaGroupEntry* first();
199 sc::FormulaGroupEntry* next();
203 * Walk through all cells in an area. For SubTotal and Aggregate depending on mnSubTotalFlags.
205 class ScCellIterator
207 typedef std::pair<sc::CellStoreType::const_iterator, size_t> PositionType;
209 ScDocument& mrDoc;
210 ScAddress maStartPos;
211 ScAddress maEndPos;
212 ScAddress maCurPos;
214 PositionType maCurColPos;
215 SubtotalFlags mnSubTotalFlags;
217 ScRefCellValue maCurCell;
219 void incBlock();
220 void incPos();
221 void setPos(size_t nPos);
223 const ScColumn* getColumn() const;
225 void init();
226 bool getCurrent();
228 public:
229 ScCellIterator( ScDocument& rDoc, const ScRange& rRange, SubtotalFlags nSubTotalFlags = SubtotalFlags::NONE );
231 const ScAddress& GetPos() const { return maCurPos; }
233 CellType getType() const { return maCurCell.getType();}
234 OUString getString() const;
235 const EditTextObject* getEditText() const { return maCurCell.getEditText();}
236 ScFormulaCell* getFormulaCell() { return maCurCell.getFormula();}
237 const ScFormulaCell* getFormulaCell() const { return maCurCell.getFormula();}
238 ScCellValue getCellValue() const;
239 const ScRefCellValue& getRefCellValue() const { return maCurCell;}
241 bool hasString() const;
242 bool isEmpty() const;
243 bool equalsWithoutFormat( const ScAddress& rPos ) const;
245 bool first();
246 bool next();
249 class ScDocAttrIterator // all attribute areas
251 private:
252 ScDocument& rDoc;
253 SCTAB nTab;
254 SCCOL nEndCol;
255 SCROW nStartRow;
256 SCROW nEndRow;
257 SCCOL nCol;
258 std::unique_ptr<ScAttrIterator>
259 pColIter;
261 public:
262 ScDocAttrIterator(ScDocument& rDocument, SCTAB nTable,
263 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
264 ~ScDocAttrIterator();
266 const ScPatternAttr* GetNext( SCCOL& rCol, SCROW& rRow1, SCROW& rRow2 );
269 class ScAttrRectIterator // all attribute areas, including areas stretching
270 // across more than one column
272 private:
273 ScDocument& rDoc;
274 SCTAB nTab;
275 SCCOL nEndCol;
276 SCROW nStartRow;
277 SCROW nEndRow;
278 SCCOL nIterStartCol;
279 SCCOL nIterEndCol;
280 std::unique_ptr<ScAttrIterator>
281 pColIter;
283 public:
284 ScAttrRectIterator(ScDocument& rDocument, SCTAB nTable,
285 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
286 ~ScAttrRectIterator();
288 void DataChanged();
289 const ScPatternAttr* GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow1, SCROW& rRow2 );
292 class ScHorizontalCellIterator // walk through all non empty cells in an area
293 { // row by row
294 struct ColParam
296 sc::CellStoreType::const_iterator maPos;
297 sc::CellStoreType::const_iterator maEnd;
298 SCCOL mnCol;
301 std::vector<ColParam>::iterator maColPos;
302 std::vector<ColParam> maColPositions;
304 ScDocument& rDoc;
305 SCTAB mnTab;
306 SCCOL nStartCol;
307 SCCOL nEndCol;
308 SCROW nStartRow;
309 SCROW nEndRow;
310 SCCOL mnCol;
311 SCROW mnRow;
312 ScRefCellValue maCurCell;
313 bool mbMore;
315 public:
316 ScHorizontalCellIterator(ScDocument& rDocument, SCTAB nTable,
317 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
318 ~ScHorizontalCellIterator();
320 ScRefCellValue* GetNext( SCCOL& rCol, SCROW& rRow );
321 bool GetPos( SCCOL& rCol, SCROW& rRow );
322 /// Set a(nother) sheet and (re)init.
323 void SetTab( SCTAB nTab );
325 private:
326 void Advance();
327 void SkipInvalid();
328 bool SkipInvalidInRow();
329 SCROW FindNextNonEmptyRow();
332 /** Row-wise value iterator. */
333 class ScHorizontalValueIterator
335 private:
336 ScDocument& rDoc;
337 const ScAttrArray* pAttrArray;
338 std::unique_ptr<ScHorizontalCellIterator>
339 pCellIter;
340 sal_uInt32 nNumFormat; // for CalcAsShown
341 SCTAB nEndTab;
342 SCCOL nCurCol;
343 SCROW nCurRow;
344 SCTAB nCurTab;
345 SCROW nAttrEndRow;
346 bool bCalcAsShown;
348 public:
350 ScHorizontalValueIterator( ScDocument& rDocument,
351 const ScRange& rRange );
352 ~ScHorizontalValueIterator();
353 /// Does NOT reset rValue if no value found!
354 bool GetNext( double& rValue, FormulaError& rErr );
357 class ScHorizontalAttrIterator
359 private:
360 ScDocument& rDoc;
361 SCTAB nTab;
362 SCCOL nStartCol;
363 SCROW nStartRow;
364 SCCOL nEndCol;
365 SCROW nEndRow;
367 std::unique_ptr<SCROW[]> pNextEnd;
368 std::unique_ptr<SCCOL[]> pHorizEnd;
369 std::unique_ptr<SCSIZE[]> pIndices;
370 std::unique_ptr<const ScPatternAttr*[]>
371 ppPatterns;
372 SCCOL nCol;
373 SCROW nRow;
374 SCROW nMinNextEnd;
376 void InitForNextRow(bool bInitialization);
378 public:
379 ScHorizontalAttrIterator( ScDocument& rDocument, SCTAB nTable,
380 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
381 ~ScHorizontalAttrIterator();
383 const ScPatternAttr* GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow );
386 // returns non-empty cells and areas with formatting (horizontal)
388 class SC_DLLPUBLIC ScUsedAreaIterator
390 private:
391 ScHorizontalCellIterator aCellIter;
392 ScHorizontalAttrIterator aAttrIter;
394 SCCOL nNextCol;
395 SCROW nNextRow;
397 SCCOL nCellCol;
398 SCROW nCellRow;
399 ScRefCellValue* pCell;
400 SCCOL nAttrCol1;
401 SCCOL nAttrCol2;
402 SCROW nAttrRow;
403 const ScPatternAttr* pPattern;
405 SCCOL nFoundStartCol; // results after GetNext
406 SCCOL nFoundEndCol;
407 SCROW nFoundRow;
408 const ScPatternAttr* pFoundPattern;
410 ScRefCellValue maFoundCell;
412 public:
413 ScUsedAreaIterator( ScDocument& rDocument, SCTAB nTable,
414 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
415 ~ScUsedAreaIterator();
417 bool GetNext();
419 SCCOL GetStartCol() const { return nFoundStartCol; }
420 SCCOL GetEndCol() const { return nFoundEndCol; }
421 SCROW GetRow() const { return nFoundRow; }
422 const ScPatternAttr* GetPattern() const { return pFoundPattern; }
423 const ScRefCellValue& GetCell() const { return maFoundCell;}
426 class ScRowBreakIterator
428 public:
429 static constexpr SCROW NOT_FOUND = -1;
431 explicit ScRowBreakIterator(::std::set<SCROW>& rBreaks);
432 SCROW first();
433 SCROW next();
435 private:
436 ::std::set<SCROW>& mrBreaks;
437 ::std::set<SCROW>::const_iterator maItr;
438 ::std::set<SCROW>::const_iterator maEnd;
441 class ScDocRowHeightUpdater
443 public:
444 struct TabRanges
446 SCTAB mnTab;
447 ScFlatBoolRowSegments maRanges;
449 TabRanges(SCTAB nTab, SCROW nMaxRow);
453 * Passing a NULL pointer to pTabRangesArray forces the heights of all
454 * rows in all tables to be updated.
456 explicit ScDocRowHeightUpdater(
457 ScDocument& rDoc, OutputDevice* pOutDev, double fPPTX, double fPPTY,
458 const ::std::vector<TabRanges>* pTabRangesArray);
460 void update();
462 private:
463 void updateAll();
465 private:
466 ScDocument& mrDoc;
467 VclPtr<OutputDevice> mpOutDev;
468 double mfPPTX;
469 double mfPPTY;
470 const ::std::vector<TabRanges>* mpTabRangesArray;
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */