1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "address.hxx"
23 #include "formulagroup.hxx"
26 #include "cellvalue.hxx"
27 #include "mtvelements.hxx"
28 #include "queryparam.hxx"
29 #include <vcl/outdev.hxx>
30 #include <vcl/vclptr.hxx>
40 class ScFlatBoolRowSegments
;
42 struct ScDBQueryParamBase
;
44 struct ScDBQueryParamInternal
;
45 struct ScDBQueryParamMatrix
;
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
;
65 SubtotalFlags mnSubTotalFlags
;
66 SvNumFormatType nNumFmtType
;
71 const sc::CellStoreType
* mpCells
;
72 PositionType maCurPos
;
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
);
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
106 FormulaError mnError
;
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
);
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
;
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
;
141 const sc::CellStoreType
* mpCells
;
142 PositionType maCurPos
;
143 ScDBQueryParamInternal
* mpParam
;
145 const ScInterpreterContext
& mrContext
;
146 const ScAttrArray
* pAttrArray
;
147 sal_uInt32 nNumFormat
; // for CalcAsShown
148 sal_uInt32 nNumFmtIndex
;
153 SvNumFormatType nNumFmtType
;
157 class DataAccessMatrix final
: public DataAccess
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
;
167 bool isValidQuery(SCROW mnRow
, const ScMatrix
& rMat
) const;
169 ScDBQueryParamMatrix
* mpParam
;
174 ::std::unique_ptr
<ScDBQueryParamBase
> mpParam
;
175 ::std::unique_ptr
<DataAccess
> mpData
;
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
193 std::vector
<sc::FormulaGroupEntry
> maEntries
;
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.
207 typedef std::pair
<sc::CellStoreType::const_iterator
, size_t> PositionType
;
210 ScAddress maStartPos
;
214 PositionType maCurColPos
;
215 SubtotalFlags mnSubTotalFlags
;
217 ScRefCellValue maCurCell
;
221 void setPos(size_t nPos
);
223 const ScColumn
* getColumn() const;
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;
249 class ScDocAttrIterator
// all attribute areas
258 std::unique_ptr
<ScAttrIterator
>
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
280 std::unique_ptr
<ScAttrIterator
>
284 ScAttrRectIterator(ScDocument
& rDocument
, SCTAB nTable
,
285 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
286 ~ScAttrRectIterator();
289 const ScPatternAttr
* GetNext( SCCOL
& rCol1
, SCCOL
& rCol2
, SCROW
& rRow1
, SCROW
& rRow2
);
292 class ScHorizontalCellIterator
// walk through all non empty cells in an area
296 sc::CellStoreType::const_iterator maPos
;
297 sc::CellStoreType::const_iterator maEnd
;
301 std::vector
<ColParam
>::iterator maColPos
;
302 std::vector
<ColParam
> maColPositions
;
312 ScRefCellValue maCurCell
;
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
);
328 bool SkipInvalidInRow();
329 SCROW
FindNextNonEmptyRow();
332 /** Row-wise value iterator. */
333 class ScHorizontalValueIterator
337 const ScAttrArray
* pAttrArray
;
338 std::unique_ptr
<ScHorizontalCellIterator
>
340 sal_uInt32 nNumFormat
; // for CalcAsShown
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
367 std::unique_ptr
<SCROW
[]> pNextEnd
;
368 std::unique_ptr
<SCCOL
[]> pHorizEnd
;
369 std::unique_ptr
<SCSIZE
[]> pIndices
;
370 std::unique_ptr
<const ScPatternAttr
*[]>
376 void InitForNextRow(bool bInitialization
);
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
391 ScHorizontalCellIterator aCellIter
;
392 ScHorizontalAttrIterator aAttrIter
;
399 ScRefCellValue
* pCell
;
403 const ScPatternAttr
* pPattern
;
405 SCCOL nFoundStartCol
; // results after GetNext
408 const ScPatternAttr
* pFoundPattern
;
410 ScRefCellValue maFoundCell
;
413 ScUsedAreaIterator( ScDocument
& rDocument
, SCTAB nTable
,
414 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
415 ~ScUsedAreaIterator();
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
429 static constexpr SCROW NOT_FOUND
= -1;
431 explicit ScRowBreakIterator(::std::set
<SCROW
>& rBreaks
);
436 ::std::set
<SCROW
>& mrBreaks
;
437 ::std::set
<SCROW
>::const_iterator maItr
;
438 ::std::set
<SCROW
>::const_iterator maEnd
;
441 class ScDocRowHeightUpdater
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
);
467 VclPtr
<OutputDevice
> mpOutDev
;
470 const ::std::vector
<TabRanges
>* mpTabRangesArray
;
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */