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/.
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"
22 //TODO: merge this with conditio.hxx
30 // don't change the order
31 // they are also used in the dialog to determine the position
33 enum ScColorScaleEntryType
38 COLORSCALE_PERCENTILE
,
44 class SC_DLLPUBLIC ScColorScaleEntry
49 std::unique_ptr
<ScFormulaCell
> mpCell
;
50 std::unique_ptr
<ScFormulaListener
> mpListener
;
51 ScColorScaleEntryType meType
;
54 ScColorScaleEntry(double nVal
, const Color
& rCol
, ScColorScaleEntryType eType
= COLORSCALE_VALUE
);
56 ScColorScaleEntry(const ScColorScaleEntry
& rEntry
);
57 ScColorScaleEntry(ScDocument
* pDoc
, const ScColorScaleEntry
& rEntry
);
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
);
91 struct SC_DLLPUBLIC ScDataBarFormatData
93 ScDataBarFormatData():
94 maAxisColor(COL_BLACK
),
97 meAxisPosition(databar::AUTOMATIC
),
102 ScDataBarFormatData(const ScDataBarFormatData
& r
):
103 maPositiveColor(r
.maPositiveColor
),
104 maAxisColor(r
.maAxisColor
),
105 mbGradient(r
.mbGradient
),
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
));
116 mpLowerLimit
.reset( new ScColorScaleEntry(*r
.mpLowerLimit
));
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
137 * Paint the bars with gradient. If this is used the default is to draw with
144 * Use different color for negative values. Color is specified in
145 * mpNegativeColor and defaults to 0xFF0000
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
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)
164 * Maximal length of a databar in percent of cell length
165 * Value has to be in the range (0, 100]
170 * If TRUE we only show the bar and not the value
174 std::unique_ptr
<ScColorScaleEntry
> mpUpperLimit
;
175 std::unique_ptr
<ScColorScaleEntry
> mpLowerLimit
;
183 IconSet_3TrafficLights1
,
184 IconSet_3TrafficLights2
,
191 IconSet_3ColorSmilies
,
196 IconSet_4TrafficLights
,
204 struct ScIconSetMap
{
210 class SC_DLLPUBLIC ScColorFormat
: public ScFormatEntry
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
;
224 std::vector
<double>& getValues() const;
226 double getMinValue() const;
227 double getMaxValue() const;
229 ScConditionalFormat
* mpParent
;
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
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;
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;
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.
284 class SC_DLLPUBLIC ScDataBarFormat
: public ScColorFormat
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.
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
;
322 * Specifies whether the icons should be shown in reverse order
325 typedef std::vector
<std::unique_ptr
<ScColorScaleEntry
>> Entries_t
;
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
):
339 ScIconSetFormatData(ScIconSetFormatData
const&);
340 ScIconSetFormatData
& operator=(ScIconSetFormatData
const&) = delete; //TODO?
343 class SC_DLLPUBLIC ScIconSetFormat
: public ScColorFormat
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
;
371 const_iterator
begin() const;
373 const_iterator
end() 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.
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
;
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */