build fix
[LibreOffice.git] / sc / inc / colorscale.hxx
blob8ae03f419b18c0713b6177c367d025c72210b520
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 #ifndef INCLUDED_SC_INC_COLORSCALE_HXX
11 #define INCLUDED_SC_INC_COLORSCALE_HXX
13 #include <formula/grammar.hxx>
14 #include <tools/color.hxx>
15 #include "rangelst.hxx"
16 #include "conditio.hxx"
17 #include "document.hxx"
19 #include <memory>
20 #include <vector>
22 //TODO: merge this with conditio.hxx
24 class ScDocument;
25 class ScFormulaCell;
26 class ScTokenArray;
27 struct ScDataBarInfo;
28 class BitmapEx;
30 // don't change the order
31 // they are also used in the dialog to determine the position
32 // in the list box
33 enum ScColorScaleEntryType
35 COLORSCALE_AUTO,
36 COLORSCALE_MIN,
37 COLORSCALE_MAX,
38 COLORSCALE_PERCENTILE,
39 COLORSCALE_VALUE,
40 COLORSCALE_PERCENT,
41 COLORSCALE_FORMULA,
44 class SC_DLLPUBLIC ScColorScaleEntry
46 private:
47 double mnVal;
48 Color maColor;
49 std::unique_ptr<ScFormulaCell> mpCell;
50 std::unique_ptr<ScFormulaListener> mpListener;
51 ScColorScaleEntryType meType;
53 public:
54 ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType = COLORSCALE_VALUE);
55 ScColorScaleEntry();
56 ScColorScaleEntry(const ScColorScaleEntry& rEntry);
57 ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
58 ~ScColorScaleEntry();
60 const Color& GetColor() const { return maColor;}
61 void SetColor(const Color&);
62 double GetValue() const;
63 void SetValue(double nValue);
64 void SetFormula(const OUString& rFormula, ScDocument* pDoc, const ScAddress& rAddr,
65 formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT);
67 void UpdateReference( sc::RefUpdateContext& rCxt );
68 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
69 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
70 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
72 const ScTokenArray* GetFormula() const;
73 OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
75 ScColorScaleEntryType GetType() const { return meType;}
76 void SetType( ScColorScaleEntryType eType );
79 namespace databar
82 enum ScAxisPosition
84 NONE,
85 AUTOMATIC,
86 MIDDLE
91 struct SC_DLLPUBLIC ScDataBarFormatData
93 ScDataBarFormatData():
94 maAxisColor(COL_BLACK),
95 mbGradient(true),
96 mbNeg(true),
97 meAxisPosition(databar::AUTOMATIC),
98 mnMinLength(0),
99 mnMaxLength(100),
100 mbOnlyBar(false){}
102 ScDataBarFormatData(const ScDataBarFormatData& r):
103 maPositiveColor(r.maPositiveColor),
104 maAxisColor(r.maAxisColor),
105 mbGradient(r.mbGradient),
106 mbNeg(r.mbNeg),
107 meAxisPosition(r.meAxisPosition),
108 mnMinLength(r.mnMinLength),
109 mnMaxLength(r.mnMaxLength),
110 mbOnlyBar(r.mbOnlyBar)
112 if(r.mpNegativeColor)
113 mpNegativeColor.reset(new Color(*r.mpNegativeColor));
115 if(r.mpLowerLimit)
116 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
117 if(r.mpUpperLimit)
118 mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
122 * Color for all Positive Values and if mbNeg == false also for negative ones
124 Color maPositiveColor;
126 * Specifies the color for negative values. This is optional and depends on mbNeg.
128 * Default color is 0xFF0000, this value is not set
130 std::unique_ptr<Color> mpNegativeColor;
132 * Color of the axis if used
133 * Default color is black
135 Color maAxisColor;
137 * Paint the bars with gradient. If this is used the default is to draw with
138 * borders.
140 * Default is true
142 bool mbGradient;
144 * Use different color for negative values. Color is specified in
145 * mpNegativeColor and defaults to 0xFF0000
147 * Default is true
149 bool mbNeg; //differentiate between negative values
151 * Paint negative values into the same direction as positive values
152 * If false we will set the mid point according to the upper and lower limit and negative
153 * values are painted to the left and positive to the right
155 * Default is false
157 databar::ScAxisPosition meAxisPosition;
159 * Minimal length of a databar in percent of cell length
160 * Value has to be in the range [0, 100)
162 double mnMinLength;
164 * Maximal length of a databar in percent of cell length
165 * Value has to be in the range (0, 100]
167 double mnMaxLength;
170 * If TRUE we only show the bar and not the value
172 bool mbOnlyBar;
174 std::unique_ptr<ScColorScaleEntry> mpUpperLimit;
175 std::unique_ptr<ScColorScaleEntry> mpLowerLimit;
178 enum ScIconSetType
180 IconSet_3Arrows,
181 IconSet_3ArrowsGray,
182 IconSet_3Flags,
183 IconSet_3TrafficLights1,
184 IconSet_3TrafficLights2,
185 IconSet_3Signs,
186 IconSet_3Symbols,
187 IconSet_3Symbols2,
188 IconSet_3Smilies,
189 IconSet_3Stars,
190 IconSet_3Triangles,
191 IconSet_3ColorSmilies,
192 IconSet_4Arrows,
193 IconSet_4ArrowsGray,
194 IconSet_4RedToBlack,
195 IconSet_4Rating,
196 IconSet_4TrafficLights,
197 IconSet_5Arrows,
198 IconSet_5ArrowsGray,
199 IconSet_5Ratings,
200 IconSet_5Quarters,
201 IconSet_5Boxes
204 struct ScIconSetMap {
205 const char* pName;
206 ScIconSetType eType;
207 sal_Int32 nElements;
210 class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
212 public:
213 ScColorFormat(ScDocument* pDoc);
214 virtual ~ScColorFormat() override;
216 const ScRangeList& GetRange() const;
218 virtual void SetParent(ScConditionalFormat* pParent) override;
220 virtual void startRendering() override;
221 virtual void endRendering() override;
223 protected:
224 std::vector<double>& getValues() const;
226 double getMinValue() const;
227 double getMaxValue() const;
229 ScConditionalFormat* mpParent;
231 private:
233 struct ScColorFormatCache
235 std::vector<double> maValues;
237 mutable std::unique_ptr<ScColorFormatCache> mpCache;
240 typedef std::vector<std::unique_ptr<ScColorScaleEntry>> ScColorScaleEntries;
242 class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
244 private:
245 ScColorScaleEntries maColorScales;
247 double GetMinValue() const;
248 double GetMaxValue() const;
250 void calcMinMax(double& nMin, double& nMax) const;
251 double CalcValue(double nMin, double nMax, ScColorScaleEntries::const_iterator& rItr) const;
252 public:
253 ScColorScaleFormat(ScDocument* pDoc);
254 ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
255 virtual ~ScColorScaleFormat() override;
256 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
258 Color* GetColor(const ScAddress& rAddr) const;
259 void AddEntry(ScColorScaleEntry* pEntry);
261 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
262 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
263 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
264 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
266 virtual condformat::ScFormatEntryType GetType() const override;
267 ScColorScaleEntries::iterator begin();
268 ScColorScaleEntries::const_iterator begin() const;
269 ScColorScaleEntries::iterator end();
270 ScColorScaleEntries::const_iterator end() const;
272 ScColorScaleEntry* GetEntry(size_t nPos);
273 const ScColorScaleEntry* GetEntry(size_t nPos) const;
275 size_t size() const;
278 * Makes sure that the maColorScales contain at least 2 entries.
279 * Should be called when it is not sure that the format is valid.
281 void EnsureSize();
284 class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
286 public:
287 ScDataBarFormat(ScDocument* pDoc);
288 ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
289 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
291 ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const;
293 void SetDataBarData( ScDataBarFormatData* pData );
294 const ScDataBarFormatData* GetDataBarData() const;
295 ScDataBarFormatData* GetDataBarData();
297 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
298 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
299 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
300 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
302 virtual condformat::ScFormatEntryType GetType() const override;
305 * Makes sure that the mpFormatData does not contain valid entries.
306 * Should be called when it is not sure that the format is valid.
308 void EnsureSize();
310 private:
311 double getMin(double nMin, double nMax) const;
312 double getMax(double nMin, double nMax) const;
314 std::unique_ptr<ScDataBarFormatData> mpFormatData;
317 struct ScIconSetFormatData
319 ScIconSetType eIconSetType;
320 bool mbShowValue;
322 * Specifies whether the icons should be shown in reverse order
324 bool mbReverse;
325 typedef std::vector<std::unique_ptr<ScColorScaleEntry>> Entries_t;
326 Entries_t m_Entries;
327 bool mbCustom;
328 // the std::pair points to exactly one image
329 // std..pair::second == -1 means no image
330 std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector;
332 ScIconSetFormatData(ScIconSetType eType = IconSet_3Arrows):
333 eIconSetType(eType),
334 mbShowValue(true),
335 mbReverse(false),
336 mbCustom(false)
339 ScIconSetFormatData(ScIconSetFormatData const&);
340 ScIconSetFormatData& operator=(ScIconSetFormatData const&) = delete; //TODO?
343 class SC_DLLPUBLIC ScIconSetFormat : public ScColorFormat
345 public:
346 ScIconSetFormat(ScDocument* pDoc);
347 ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
349 virtual ScColorFormat* Clone(ScDocument* pDoc) const override;
351 ScIconSetInfo* GetIconSetInfo(const ScAddress& rAddr) const;
353 void SetIconSetData( ScIconSetFormatData* pData );
354 const ScIconSetFormatData* GetIconSetData() const;
355 ScIconSetFormatData* GetIconSetData();
357 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override;
358 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) override;
359 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) override;
360 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) override;
362 virtual condformat::ScFormatEntryType GetType() const override;
364 static const ScIconSetMap g_IconSetMap[];
365 static BitmapEx& getBitmap(sc::IconSetBitmapMap& rBitmapMap, ScIconSetType eType, sal_Int32 nIndex);
367 typedef ScIconSetFormatData::Entries_t::iterator iterator;
368 typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator;
370 iterator begin();
371 const_iterator begin() const;
372 iterator end();
373 const_iterator end() const;
375 size_t size() const;
378 * Makes sure that the mpFormatData does not contain valid entries.
379 * Should be called when it is not sure that the format is valid.
381 void EnsureSize();
383 private:
385 double GetMinValue() const;
386 double GetMaxValue() const;
387 double CalcValue(double nMin, double nMax, ScIconSetFormat::const_iterator& itr) const;
389 std::unique_ptr<ScIconSetFormatData> mpFormatData;
392 #endif
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */