Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / dpoutput.hxx
blob94decfa444660fe90df9d7158a146e825c24942f
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 <com/sun/star/sheet/DataPilotOutputRangeType.hpp>
23 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
24 #include <com/sun/star/uno/Sequence.hxx>
26 #include <tools/long.hxx>
28 #include "address.hxx"
30 #include "dptypes.hxx"
32 #include <memory>
33 #include <vector>
35 namespace com::sun::star::sheet {
36 struct DataPilotFieldFilter;
37 struct DataPilotTablePositionData;
38 struct DataResult;
39 struct MemberResult;
40 class XDimensionsSupplier;
42 namespace tools { class Rectangle; }
43 class ScDocument;
44 struct ScDPOutLevelData;
46 class ScDPOutput
48 private:
49 ScDocument* pDoc;
50 css::uno::Reference< css::sheet::XDimensionsSupplier> xSource;
51 ScAddress aStartPos;
52 std::vector<ScDPOutLevelData> pColFields;
53 std::vector<ScDPOutLevelData> pRowFields;
54 std::vector<ScDPOutLevelData> pPageFields;
55 css::uno::Sequence< css::uno::Sequence< css::sheet::DataResult> > aData;
56 OUString aDataDescription;
58 // Number format related parameters
59 std::unique_ptr<sal_uInt32[]>
60 pColNumFmt;
61 std::unique_ptr<sal_uInt32[]>
62 pRowNumFmt;
63 std::vector<bool> aRowCompactFlags;
64 sal_Int32 nColFmtCount;
65 sal_Int32 nRowFmtCount;
66 sal_uInt32 nSingleNumFmt;
67 size_t nRowDims; // Including empty ones.
69 // Output geometry related parameters
70 sal_Int32 nColCount;
71 sal_Int32 nRowCount;
72 sal_Int32 nHeaderSize;
73 SCCOL nTabStartCol;
74 SCROW nTabStartRow;
75 SCCOL nMemberStartCol;
76 SCROW nMemberStartRow;
77 SCCOL nDataStartCol;
78 SCROW nDataStartRow;
79 SCCOL nTabEndCol;
80 SCROW nTabEndRow;
81 bool bDoFilter:1;
82 bool bResultsError:1;
83 bool bSizesValid:1;
84 bool bSizeOverflow:1;
85 bool mbHeaderLayout:1; // true : grid, false : standard
86 bool mbHasCompactRowField:1; // true: at least one of the row fields has compact layout.
87 bool mbExpandCollapse:1; // true: show expand/collapse buttons
89 void DataCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
90 const css::sheet::DataResult& rData );
91 void HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
92 const css::sheet::MemberResult& rData,
93 bool bColHeader, tools::Long nLevel );
95 void FieldCell(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScDPOutLevelData& rData, bool bInTable);
96 void MultiFieldCell(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bRowField);
98 /// Computes number of columns needed to write row fields.
99 SCCOL GetColumnsForRowFields() const;
100 void CalcSizes();
102 /** Query which sub-area of the table the cell is in. See
103 css.sheet.DataPilotTablePositionType for the interpretation of the
104 return value. */
105 sal_Int32 GetPositionType(const ScAddress& rPos);
106 /// Returns the range of row fields that are contained by table's row fields column nCol.
107 void GetRowFieldRange(SCCOL nCol, sal_Int32& nRowFieldStart, sal_Int32& nRowFieldEnd) const;
108 /// Find row field index from row position in case of compact layout.
109 sal_Int32 GetRowFieldCompact(SCCOL nColQuery, SCROW nRowQuery) const;
111 public:
112 ScDPOutput( ScDocument* pD,
113 css::uno::Reference< css::sheet::XDimensionsSupplier> xSrc,
114 const ScAddress& rPos, bool bFilter, bool bExpandCollapse );
115 ~ScDPOutput();
117 void SetPosition( const ScAddress& rPos );
119 void Output(); //! Refresh?
120 ScRange GetOutputRange( sal_Int32 nRegionType = css::sheet::DataPilotOutputRangeType::WHOLE );
121 sal_Int32 GetHeaderRows() const;
122 bool HasError(); // range overflow or exception from source
124 void GetPositionData(const ScAddress& rPos, css::sheet::DataPilotTablePositionData& rPosData);
126 /** Get filtering criteria based on the position of the cell within data
127 field region. */
128 bool GetDataResultPositionData(::std::vector< css::sheet::DataPilotFieldFilter >& rFilters, const ScAddress& rPos);
130 tools::Long GetHeaderDim( const ScAddress& rPos, css::sheet::DataPilotFieldOrientation& rOrient );
131 bool GetHeaderDrag(
132 const ScAddress& rPos, bool bMouseLeft, bool bMouseTop, tools::Long nDragDim,
133 tools::Rectangle& rPosRect, css::sheet::DataPilotFieldOrientation& rOrient, tools::Long& rDimPos );
134 bool IsFilterButton( const ScAddress& rPos );
136 void GetMemberResultNames(ScDPUniqueStringSet& rNames, tools::Long nDimension);
138 void SetHeaderLayout(bool bUseGrid);
139 bool GetHeaderLayout() const { return mbHeaderLayout;}
141 static void GetDataDimensionNames(
142 OUString& rSourceName, OUString& rGivenName,
143 const css::uno::Reference< css::uno::XInterface>& xDim );
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */