tdf#48459 sw inline heading: don't apply inside frames or over 120 chars
[LibreOffice.git] / sc / inc / colorscale.hxx
blob373c06eda05cdf5770ee5671ea5b76456b428e40
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/.
8 */
10 #pragma once
12 #include <formula/grammar.hxx>
13 #include <tools/color.hxx>
14 #include "conditio.hxx"
15 #include "document.hxx"
17 #include <memory>
18 #include <vector>
19 #include <optional>
21 //TODO: merge this with conditio.hxx
23 class ScFormulaCell;
24 class ScTokenArray;
25 struct ScDataBarInfo;
26 class BitmapEx;
28 // don't change the order
29 // they are also used in the dialog to determine the position
30 // in the list box
31 enum ScColorScaleEntryType
33 COLORSCALE_AUTO,
34 COLORSCALE_MIN,
35 COLORSCALE_MAX,
36 COLORSCALE_PERCENTILE,
37 COLORSCALE_VALUE,
38 COLORSCALE_PERCENT,
39 COLORSCALE_FORMULA,
42 class ScColorScaleEntry
44 private:
45 double mnVal;
46 std::unique_ptr<ScFormulaCell> mpCell;
47 std::unique_ptr<ScFormulaListener> mpListener;
48 ScConditionalFormat* mpFormat;
49 Color maColor;
50 ScColorScaleEntryType meType;
51 bool mbGreaterThanOrEqual;
53 void setListener();
55 public:
56 SC_DLLPUBLIC ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType = COLORSCALE_VALUE);
57 SC_DLLPUBLIC ScColorScaleEntry();
58 ScColorScaleEntry(const ScColorScaleEntry& rEntry);
59 ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
60 SC_DLLPUBLIC ~ScColorScaleEntry() COVERITY_NOEXCEPT_FALSE;
62 const Color& GetColor() const { return maColor;}
63 void SetColor(const Color&);
64 SC_DLLPUBLIC double GetValue() const;
65 SC_DLLPUBLIC void SetValue(double nValue);
66 SC_DLLPUBLIC bool GetGreaterThanOrEqual() const;
67 SC_DLLPUBLIC void SetGreaterThanOrEqual(bool bGreaterThanOrEqual);
68 SC_DLLPUBLIC void SetFormula(const OUString& rFormula, ScDocument& rDoc, const ScAddress& rAddr,
69 formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT);
71 void UpdateReference( const sc::RefUpdateContext& rCxt );
72 void UpdateInsertTab( const sc::RefUpdateInsertTabContext& rCxt );
73 void UpdateDeleteTab( const sc::RefUpdateDeleteTabContext& rCxt );
74 void UpdateMoveTab( const sc::RefUpdateMoveTabContext& rCxt );
76 SC_DLLPUBLIC const ScTokenArray* GetFormula() const;
77 SC_DLLPUBLIC OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
79 ScColorScaleEntryType GetType() const { return meType;}
80 SC_DLLPUBLIC void SetType( ScColorScaleEntryType eType );
82 void SetRepaintCallback(ScConditionalFormat* pParent);
83 void SetRepaintCallback(const std::function<void()>& func);
86 namespace databar
89 enum ScAxisPosition
91 NONE,
92 AUTOMATIC,
93 MIDDLE
98 struct SC_DLLPUBLIC ScDataBarFormatData
100 ScDataBarFormatData():
101 maAxisColor(COL_BLACK),
102 mbGradient(true),
103 mbNeg(true),
104 meAxisPosition(databar::AUTOMATIC),
105 mnMinLength(0),
106 mnMaxLength(100),
107 mbOnlyBar(false),
108 mpUpperLimit(new ScColorScaleEntry()),
109 mpLowerLimit(new ScColorScaleEntry())
112 ScDataBarFormatData(const ScDataBarFormatData& r):
113 maPositiveColor(r.maPositiveColor),
114 maAxisColor(r.maAxisColor),
115 mbGradient(r.mbGradient),
116 mbNeg(r.mbNeg),
117 meAxisPosition(r.meAxisPosition),
118 mnMinLength(r.mnMinLength),
119 mnMaxLength(r.mnMaxLength),
120 mbOnlyBar(r.mbOnlyBar)
122 mxNegativeColor = r.mxNegativeColor;
124 if(r.mpLowerLimit)
125 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
126 else
127 mpLowerLimit.reset(new ScColorScaleEntry());
128 if(r.mpUpperLimit)
129 mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
130 else
131 mpUpperLimit.reset(new ScColorScaleEntry());
135 * Color for all Positive Values and if mbNeg == false also for negative ones
137 Color maPositiveColor;
139 * Specifies the color for negative values. This is optional and depends on mbNeg.
141 * Default color is 0xFF0000, this value is not set
143 std::optional<Color> mxNegativeColor;
145 * Color of the axis if used
146 * Default color is black
148 Color maAxisColor;
150 * Paint the bars with gradient. If this is used the default is to draw with
151 * borders.
153 * Default is true
155 bool mbGradient;
157 * Use different color for negative values. Color is specified in
158 * mpNegativeColor and defaults to 0xFF0000
160 * Default is true
162 bool mbNeg; //differentiate between negative values
164 * Paint negative values into the same direction as positive values
165 * If false we will set the mid point according to the upper and lower limit and negative
166 * values are painted to the left and positive to the right
168 * Default is false
170 databar::ScAxisPosition meAxisPosition;
172 * Minimal length of a databar in percent of cell length
173 * Value has to be in the range [0, 100)
175 double mnMinLength;
177 * Maximal length of a databar in percent of cell length
178 * Value has to be in the range (0, 100]
180 double mnMaxLength;
183 * If TRUE we only show the bar and not the value
185 bool mbOnlyBar;
187 std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpUpperLimit;
188 std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>> mpLowerLimit;
191 enum ScIconSetType
193 IconSet_3Arrows,
194 IconSet_3ArrowsGray,
195 IconSet_3Flags,
196 IconSet_3TrafficLights1,
197 IconSet_3TrafficLights2,
198 IconSet_3Signs,
199 IconSet_3Symbols,
200 IconSet_3Symbols2,
201 IconSet_3Smilies,
202 IconSet_3Stars,
203 IconSet_3Triangles,
204 IconSet_3ColorSmilies,
205 IconSet_4Arrows,
206 IconSet_4ArrowsGray,
207 IconSet_4RedToBlack,
208 IconSet_4Rating,
209 IconSet_4TrafficLights,
210 IconSet_5Arrows,
211 IconSet_5ArrowsGray,
212 IconSet_5Ratings,
213 IconSet_5Quarters,
214 IconSet_5Boxes
217 struct ScIconSetMap {
218 OUString aName;
219 ScIconSetType eType;
220 sal_Int32 nElements;
223 class SAL_DLLPUBLIC_RTTI ScColorFormat : public ScFormatEntry
225 public:
226 ScColorFormat(ScDocument* pDoc);
227 SC_DLLPUBLIC virtual ~ScColorFormat() override;
229 SC_DLLPUBLIC const ScRangeList& GetRange() const;
230 void SetCache(const std::vector<double>& aValues) const;
231 std::vector<double> GetCache() const;
233 virtual void SetParent(ScConditionalFormat* pParent) override;
235 virtual void startRendering() override;
236 virtual void endRendering() override;
237 virtual void updateValues() override;
239 protected:
240 std::vector<double>& getValues() const;
242 double getMinValue() const;
243 double getMaxValue() const;
245 ScConditionalFormat* mpParent;
248 typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>>> ScColorScaleEntries;
250 class SAL_DLLPUBLIC_RTTI ScColorScaleFormat final : public ScColorFormat
252 private:
253 ScColorScaleEntries maColorScales;
255 double GetMinValue() const;
256 double GetMaxValue() const;
258 void calcMinMax(double& nMin, double& nMax) const;
259 double CalcValue(double nMin, double nMax, const ScColorScaleEntries::const_iterator& rItr) const;
260 public:
261 SC_DLLPUBLIC ScColorScaleFormat(ScDocument* pDoc);
262 ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
263 ScColorScaleFormat(const ScColorScaleFormat&) = delete;
264 virtual ~ScColorScaleFormat() override;
265 const ScColorScaleFormat& operator=(const ScColorScaleFormat&) = delete;
267 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
269 virtual void SetParent(ScConditionalFormat* pParent) override;
271 SC_DLLPUBLIC std::optional<Color> GetColor(const ScAddress& rAddr) const;
272 SC_DLLPUBLIC void AddEntry(ScColorScaleEntry* pEntry);
274 bool IsEqual(const ScFormatEntry& r, bool bIgnoreSrcPos) const override;
276 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
277 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
278 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
279 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
281 virtual Type GetType() const override;
282 ScColorScaleEntries::iterator begin();
283 SC_DLLPUBLIC ScColorScaleEntries::const_iterator begin() const;
284 ScColorScaleEntries::iterator end();
285 SC_DLLPUBLIC ScColorScaleEntries::const_iterator end() const;
287 ScColorScaleEntry* GetEntry(size_t nPos);
288 SC_DLLPUBLIC const ScColorScaleEntry* GetEntry(size_t nPos) const;
290 SC_DLLPUBLIC size_t size() const;
293 * Makes sure that the maColorScales contain at least 2 entries.
294 * Should be called when it is not sure that the format is valid.
296 void EnsureSize();
299 class SAL_DLLPUBLIC_RTTI ScDataBarFormat final : public ScColorFormat
301 public:
302 SC_DLLPUBLIC ScDataBarFormat(ScDocument* pDoc);
303 ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
304 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
306 virtual void SetParent(ScConditionalFormat* pParent) override;
308 std::unique_ptr<ScDataBarInfo> GetDataBarInfo(const ScAddress& rAddr) const;
310 SC_DLLPUBLIC void SetDataBarData( ScDataBarFormatData* pData );
311 SC_DLLPUBLIC const ScDataBarFormatData* GetDataBarData() const;
312 SC_DLLPUBLIC ScDataBarFormatData* GetDataBarData();
314 bool IsEqual(const ScFormatEntry& r, bool bIgnoreSrcPos) const override;
316 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
317 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
318 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
319 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
321 virtual Type GetType() const override;
324 * Makes sure that the mpFormatData does not contain valid entries.
325 * Should be called when it is not sure that the format is valid.
327 void EnsureSize();
329 private:
330 double getMin(double nMin, double nMax) const;
331 double getMax(double nMin, double nMax) const;
333 std::unique_ptr<ScDataBarFormatData> mpFormatData;
336 struct ScIconSetFormatData
338 ScIconSetType eIconSetType;
339 bool mbShowValue;
341 * Specifies whether the icons should be shown in reverse order
343 bool mbReverse;
344 typedef std::vector<std::unique_ptr<ScColorScaleEntry, o3tl::default_delete<ScColorScaleEntry>>> Entries_t;
345 Entries_t m_Entries;
346 bool mbCustom;
347 // the std::pair points to exactly one image
348 // std..pair::second == -1 means no image
349 std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector;
351 ScIconSetFormatData(ScIconSetType eType = IconSet_3Arrows):
352 eIconSetType(eType),
353 mbShowValue(true),
354 mbReverse(false),
355 mbCustom(false)
358 ScIconSetFormatData(ScIconSetFormatData const&);
359 ScIconSetFormatData& operator=(ScIconSetFormatData const&) = delete; //TODO?
362 class SAL_DLLPUBLIC_RTTI ScIconSetFormat final : public ScColorFormat
364 public:
365 SC_DLLPUBLIC ScIconSetFormat(ScDocument* pDoc);
366 ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
368 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
370 virtual void SetParent(ScConditionalFormat* pParent) override;
372 SC_DLLPUBLIC std::unique_ptr<ScIconSetInfo> GetIconSetInfo(const ScAddress& rAddr) const;
374 SC_DLLPUBLIC void SetIconSetData( ScIconSetFormatData* pData );
375 SC_DLLPUBLIC const ScIconSetFormatData* GetIconSetData() const;
376 ScIconSetFormatData* GetIconSetData();
378 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
379 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
380 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
381 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
383 virtual Type GetType() const override;
385 SC_DLLPUBLIC static const ScIconSetMap g_IconSetMap[];
386 SC_DLLPUBLIC static OUString getIconSetName( ScIconSetType eType );
387 static sal_Int32 getIconSetElements( ScIconSetType eType );
388 static OUString getIconName(ScIconSetType eType, sal_Int32 nIndex);
389 static BitmapEx& getBitmap(sc::IconSetBitmapMap& rBitmapMap, ScIconSetType eType, sal_Int32 nIndex);
391 typedef ScIconSetFormatData::Entries_t::iterator iterator;
392 typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator;
394 iterator begin();
395 SC_DLLPUBLIC const_iterator begin() const;
396 iterator end();
397 SC_DLLPUBLIC const_iterator end() const;
399 size_t size() const;
402 * Makes sure that the mpFormatData does not contain valid entries.
403 * Should be called when it is not sure that the format is valid.
405 void EnsureSize();
407 private:
409 double GetMinValue() const;
410 double GetMaxValue() const;
411 double CalcValue(double nMin, double nMax, const ScIconSetFormat::const_iterator& itr) const;
413 std::unique_ptr<ScIconSetFormatData> mpFormatData;
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */