/src/libreoffice/sc/inc/fillinfo.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <memory> |
25 | | |
26 | | #include <svx/framelinkarray.hxx> |
27 | | #include "colorscale.hxx" |
28 | | #include "cellvalue.hxx" |
29 | | #include <o3tl/typed_flags_set.hxx> |
30 | | #include <optional> |
31 | | |
32 | | class SvxBoxItem; |
33 | | class SvxLineItem; |
34 | | class SvxShadowItem; |
35 | | |
36 | | class ScPatternAttr; |
37 | | |
38 | | enum class ScRotateDir : sal_uInt8 { |
39 | | NONE, Standard, Left, Right, Center |
40 | | }; |
41 | | |
42 | | enum class ScClipMark : sal_uInt8 { |
43 | | NONE = 0x00, Left = 0x01, Right = 0x02, Bottom = 0x03, Top = 0x04 |
44 | | }; |
45 | | namespace o3tl { |
46 | | template<> struct typed_flags<ScClipMark> : is_typed_flags<ScClipMark, 0x07> {}; |
47 | | } |
48 | | |
49 | | const sal_uInt8 SC_CLIPMARK_SIZE = 64; |
50 | | |
51 | | enum ScShadowPart |
52 | | { |
53 | | SC_SHADOW_HSTART, |
54 | | SC_SHADOW_VSTART, |
55 | | SC_SHADOW_HORIZ, |
56 | | SC_SHADOW_VERT, |
57 | | SC_SHADOW_CORNER |
58 | | }; |
59 | | |
60 | | struct ScDataBarInfo |
61 | | { |
62 | | double mnZero; // 0 to 100 |
63 | | Color maColor; |
64 | | double mnLength; // -100 to 100 |
65 | | bool mbGradient; |
66 | | bool mbShowValue; |
67 | | Color maAxisColor; |
68 | | |
69 | | bool operator==(const ScDataBarInfo& r) const |
70 | 0 | { |
71 | 0 | if( mnZero != r.mnZero ) |
72 | 0 | return false; |
73 | 0 | if( maColor != r.maColor ) |
74 | 0 | return false; |
75 | 0 | if(mnLength != r.mnLength) |
76 | 0 | return false; |
77 | 0 | if (mbGradient != r.mbGradient) |
78 | 0 | return false; |
79 | | |
80 | 0 | return true; |
81 | 0 | } |
82 | | |
83 | | bool operator!=(const ScDataBarInfo& r) const |
84 | 0 | { |
85 | 0 | return !(*this == r); |
86 | 0 | } |
87 | | }; |
88 | | |
89 | | struct ScIconSetInfo |
90 | | { |
91 | | sal_Int32 nIconIndex; |
92 | | ScIconSetType eIconSetType; |
93 | | ScConditionMode eConditionMode; |
94 | | tools::Long mnHeight = 0; |
95 | | bool mbShowValue; |
96 | | }; |
97 | | |
98 | | // FillInfo() computes some info for all cells starting from column 0, |
99 | | // but most of the info is needed only for cells in the given columns. |
100 | | // Keeping all the info in ScCellInfo could lead to allocation and initialization |
101 | | // of MiB's of memory, so split the info needed for all cells to a smaller structure. |
102 | | struct ScBasicCellInfo |
103 | | { |
104 | | ScBasicCellInfo() |
105 | 0 | : nWidth(0) |
106 | 0 | , bEmptyCellText(true) |
107 | 0 | , bEditEngine(false) // view-internal |
108 | 0 | {} |
109 | | sal_uInt16 nWidth; |
110 | | bool bEmptyCellText : 1; |
111 | | bool bEditEngine : 1; // output-internal |
112 | | }; |
113 | | |
114 | | struct ScCellInfo |
115 | | { |
116 | | ScCellInfo() |
117 | 0 | : pConditionSet(nullptr) |
118 | 0 | , pTableFormatSet(nullptr) |
119 | 0 | , pDataBar(nullptr) |
120 | 0 | , pIconSet(nullptr) |
121 | 0 | , maBackground() |
122 | 0 | , maLinesAttr() |
123 | 0 | , mpTLBRLine(nullptr) |
124 | 0 | , mpBLTRLine(nullptr) |
125 | 0 | , pShadowAttr(nullptr) |
126 | 0 | , pHShadowOrigin(nullptr) |
127 | 0 | , pVShadowOrigin(nullptr) |
128 | 0 | , eHShadowPart(SC_SHADOW_HSTART) |
129 | 0 | , eVShadowPart(SC_SHADOW_HSTART) |
130 | 0 | , nClipMark(ScClipMark::NONE) |
131 | 0 | , nRotateDir(ScRotateDir::NONE) |
132 | 0 | , bMerged(false) |
133 | 0 | , bHOverlapped(false) |
134 | 0 | , bVOverlapped(false) |
135 | 0 | , bAutoFilter(false) |
136 | 0 | , bPivotButton(false) |
137 | 0 | , bPivotPopupButton(false) |
138 | 0 | , bFilterActive(false) |
139 | 0 | , bPrinted(false) // view-internal |
140 | 0 | , bHideGrid(false) // view-internal |
141 | 0 | , bPivotCollapseButton(false) |
142 | 0 | , bPivotExpandButton(false) |
143 | 0 | , bPivotPopupButtonMulti(false) |
144 | 0 | { |
145 | 0 | } |
146 | | |
147 | | ScCellInfo(const ScCellInfo&) = delete; |
148 | | const ScCellInfo& operator=(const ScCellInfo&) = delete; |
149 | | |
150 | | ScRefCellValue maCell; |
151 | | |
152 | | // This is not ideal, both for efficiency and correctness. |
153 | | // (a) It costs cycles to ref-count the underlying ScPatternAttr here. |
154 | | // (b) We can also end up pointing at an incorrect ScPatternAttr. |
155 | | // This is because, during painting, calculation side-effects can end up mutating the underlying cell |
156 | | // attributes. Rather than pay the cost of fetching the right thing repeatedly during painting, we |
157 | | // tolerate a little bit of (hopefully) temporary incorrectness. |
158 | | CellAttributeHolder pPatternAttr; |
159 | | const SfxItemSet* pConditionSet; |
160 | | const SfxItemSet* pTableFormatSet; |
161 | | std::optional<Color> mxColorScale; |
162 | | const ScDataBarInfo* pDataBar; |
163 | | const ScIconSetInfo* pIconSet; |
164 | | |
165 | | SfxPoolItemHolder maBackground; |
166 | | SfxPoolItemHolder maLinesAttr; |
167 | | |
168 | | const SvxLineItem* mpTLBRLine; /// original item from document. |
169 | | const SvxLineItem* mpBLTRLine; /// original item from document. |
170 | | |
171 | | const SvxShadowItem* pShadowAttr; // original item (internal) |
172 | | |
173 | | const SvxShadowItem* pHShadowOrigin; |
174 | | const SvxShadowItem* pVShadowOrigin; |
175 | | |
176 | | ScShadowPart eHShadowPart : 4; // shadow effective for drawing |
177 | | ScShadowPart eVShadowPart : 4; |
178 | | ScClipMark nClipMark; |
179 | | ScRotateDir nRotateDir; |
180 | | |
181 | | bool bMerged : 1; |
182 | | bool bHOverlapped : 1; |
183 | | bool bVOverlapped : 1; |
184 | | bool bAutoFilter : 1; |
185 | | bool bPivotButton:1; |
186 | | bool bPivotPopupButton:1; |
187 | | bool bFilterActive:1; |
188 | | bool bPrinted : 1; // when required (pagebreak mode) |
189 | | bool bHideGrid : 1; // output-internal |
190 | | bool bPivotCollapseButton : 1; // dp compact layout collapse button |
191 | | bool bPivotExpandButton : 1; // dp compact layout expand button |
192 | | bool bPivotPopupButtonMulti : 1; // dp button with popup arrow for multiple fields |
193 | | |
194 | 0 | const ScPatternAttr* getPatternAttr() const { return pPatternAttr.getScPatternAttr(); } |
195 | | }; |
196 | | |
197 | | const SCCOL SC_ROTMAX_NONE = SCCOL_MAX; |
198 | | |
199 | | struct RowInfo |
200 | | { |
201 | | RowInfo() = default; |
202 | | RowInfo(const RowInfo&) = delete; |
203 | | const RowInfo& operator=(const RowInfo&) = delete; |
204 | | |
205 | | ScCellInfo& cellInfo(SCCOL nCol) |
206 | 0 | { |
207 | 0 | assert( nCol >= nStartCol - 1 ); |
208 | | #ifdef DBG_UTIL |
209 | | assert( nCol <= nEndCol + 1 ); |
210 | | #endif |
211 | 0 | return pCellInfo[ nCol - nStartCol + 1 ]; |
212 | 0 | } |
213 | | const ScCellInfo& cellInfo(SCCOL nCol) const |
214 | 0 | { |
215 | 0 | return const_cast<RowInfo*>(this)->cellInfo(nCol); |
216 | 0 | } |
217 | | |
218 | | ScBasicCellInfo& basicCellInfo(SCCOL nCol) |
219 | 0 | { |
220 | 0 | assert( nCol >= -1 ); |
221 | | #ifdef DBG_UTIL |
222 | | assert( nCol <= nEndCol + 1 ); |
223 | | #endif |
224 | 0 | return pBasicCellInfo[ nCol + 1 ]; |
225 | 0 | } |
226 | | const ScBasicCellInfo& basicCellInfo(SCCOL nCol) const |
227 | 0 | { |
228 | 0 | return const_cast<RowInfo*>(this)->basicCellInfo(nCol); |
229 | 0 | } |
230 | | |
231 | | void allocCellInfo(SCCOL startCol, SCCOL endCol) |
232 | 0 | { |
233 | 0 | nStartCol = startCol; |
234 | | #ifdef DBG_UTIL |
235 | | nEndCol = endCol; |
236 | | #endif |
237 | 0 | pCellInfo = new ScCellInfo[ endCol - nStartCol + 1 + 2 ]; |
238 | 0 | pBasicCellInfo = new ScBasicCellInfo[ endCol + 1 + 2 ]; |
239 | 0 | } |
240 | | void freeCellInfo() |
241 | 0 | { |
242 | 0 | delete[] pCellInfo; |
243 | 0 | delete[] pBasicCellInfo; |
244 | 0 | } |
245 | | |
246 | | sal_uInt16 nHeight; |
247 | | SCROW nRowNo; |
248 | | SCCOL nRotMaxCol; // SC_ROTMAX_NONE, if nothing |
249 | | |
250 | | bool bEmptyBack:1; |
251 | | bool bAutoFilter:1; |
252 | | bool bPivotButton:1; |
253 | | bool bChanged:1; // TRUE, if not tested |
254 | | bool bPivotToggle:1; |
255 | | |
256 | | private: |
257 | | // This class allocates ScCellInfo with also one item extra before and after. |
258 | | // To make handling easier, this is private and access functions take care of adjusting |
259 | | // the array indexes and error-checking. ScCellInfo is allocated only for a given |
260 | | // range of columns plus one on each side, ScBasicCellInfo is allocated for columns |
261 | | // starting from column 0 until the last column given, again plus one on each side. |
262 | | ScCellInfo* pCellInfo; |
263 | | ScBasicCellInfo* pBasicCellInfo; |
264 | | SCCOL nStartCol; |
265 | | #ifdef DBG_UTIL |
266 | | SCCOL nEndCol; |
267 | | #endif |
268 | | }; |
269 | | |
270 | | struct ScTableInfo |
271 | | { |
272 | | svx::frame::Array maArray; |
273 | | std::unique_ptr<RowInfo[]> |
274 | | mpRowInfo; |
275 | | SCSIZE mnArrCount; |
276 | | SCSIZE mnArrCapacity; |
277 | | bool mbPageMode; |
278 | | |
279 | | explicit ScTableInfo(SCROW nStartRow, SCROW nEndRow, bool bHintOnly); |
280 | | ~ScTableInfo(); |
281 | | ScTableInfo(const ScTableInfo&) = delete; |
282 | | const ScTableInfo& operator=(const ScTableInfo&) = delete; |
283 | | |
284 | | void addDataBarInfo(std::unique_ptr<const ScDataBarInfo> info) |
285 | 0 | { |
286 | 0 | mDataBarInfos.push_back(std::move(info)); |
287 | 0 | } |
288 | | void addIconSetInfo(std::unique_ptr<const ScIconSetInfo> info) |
289 | 0 | { |
290 | 0 | mIconSetInfos.push_back(std::move(info)); |
291 | 0 | } |
292 | | private: |
293 | | // These are owned here and not in ScCellInfo to avoid freeing |
294 | | // memory for every pointer in ScCellInfo, most of which are nullptr. |
295 | | std::vector<std::unique_ptr<const ScDataBarInfo>> mDataBarInfos; |
296 | | std::vector<std::unique_ptr<const ScIconSetInfo>> mIconSetInfos; |
297 | | }; |
298 | | |
299 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |