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 "conditio.hxx"
16 #include "document.hxx"
21 //TODO: merge this with conditio.hxx
28 // don't change the order
29 // they are also used in the dialog to determine the position
31 enum ScColorScaleEntryType
36 COLORSCALE_PERCENTILE
,
42 class SC_DLLPUBLIC ScColorScaleEntry
46 std::unique_ptr
<ScFormulaCell
> mpCell
;
47 std::unique_ptr
<ScFormulaListener
> mpListener
;
48 ScConditionalFormat
* mpFormat
;
50 ScColorScaleEntryType meType
;
55 ScColorScaleEntry(double nVal
, const Color
& rCol
, ScColorScaleEntryType eType
= COLORSCALE_VALUE
);
57 ScColorScaleEntry(const ScColorScaleEntry
& rEntry
);
58 ScColorScaleEntry(ScDocument
* pDoc
, const ScColorScaleEntry
& rEntry
);
59 ~ScColorScaleEntry() COVERITY_NOEXCEPT_FALSE
;
61 const Color
& GetColor() const { return maColor
;}
62 void SetColor(const Color
&);
63 double GetValue() const;
64 void SetValue(double nValue
);
65 void SetFormula(const OUString
& rFormula
, ScDocument
* pDoc
, const ScAddress
& rAddr
,
66 formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
68 void UpdateReference( const sc::RefUpdateContext
& rCxt
);
69 void UpdateInsertTab( const sc::RefUpdateInsertTabContext
& rCxt
);
70 void UpdateDeleteTab( const sc::RefUpdateDeleteTabContext
& rCxt
);
71 void UpdateMoveTab( const sc::RefUpdateMoveTabContext
& rCxt
);
73 const ScTokenArray
* GetFormula() const;
74 OUString
GetFormula( formula::FormulaGrammar::Grammar eGrammar
) const;
76 ScColorScaleEntryType
GetType() const { return meType
;}
77 void SetType( ScColorScaleEntryType eType
);
79 void SetRepaintCallback(ScConditionalFormat
* pParent
);
80 void SetRepaintCallback(const std::function
<void()>& func
);
95 struct SC_DLLPUBLIC ScDataBarFormatData
97 ScDataBarFormatData():
98 maAxisColor(COL_BLACK
),
101 meAxisPosition(databar::AUTOMATIC
),
105 mpUpperLimit(new ScColorScaleEntry()),
106 mpLowerLimit(new ScColorScaleEntry())
109 ScDataBarFormatData(const ScDataBarFormatData
& r
):
110 maPositiveColor(r
.maPositiveColor
),
111 maAxisColor(r
.maAxisColor
),
112 mbGradient(r
.mbGradient
),
114 meAxisPosition(r
.meAxisPosition
),
115 mnMinLength(r
.mnMinLength
),
116 mnMaxLength(r
.mnMaxLength
),
117 mbOnlyBar(r
.mbOnlyBar
)
119 if(r
.mpNegativeColor
)
120 mpNegativeColor
.reset(new Color(*r
.mpNegativeColor
));
123 mpLowerLimit
.reset( new ScColorScaleEntry(*r
.mpLowerLimit
));
125 mpLowerLimit
.reset(new ScColorScaleEntry());
127 mpUpperLimit
.reset( new ScColorScaleEntry(*r
.mpUpperLimit
));
129 mpUpperLimit
.reset(new ScColorScaleEntry());
133 * Color for all Positive Values and if mbNeg == false also for negative ones
135 Color maPositiveColor
;
137 * Specifies the color for negative values. This is optional and depends on mbNeg.
139 * Default color is 0xFF0000, this value is not set
141 std::unique_ptr
<Color
> mpNegativeColor
;
143 * Color of the axis if used
144 * Default color is black
148 * Paint the bars with gradient. If this is used the default is to draw with
155 * Use different color for negative values. Color is specified in
156 * mpNegativeColor and defaults to 0xFF0000
160 bool mbNeg
; //differentiate between negative values
162 * Paint negative values into the same direction as positive values
163 * If false we will set the mid point according to the upper and lower limit and negative
164 * values are painted to the left and positive to the right
168 databar::ScAxisPosition meAxisPosition
;
170 * Minimal length of a databar in percent of cell length
171 * Value has to be in the range [0, 100)
175 * Maximal length of a databar in percent of cell length
176 * Value has to be in the range (0, 100]
181 * If TRUE we only show the bar and not the value
185 std::unique_ptr
<ScColorScaleEntry
> mpUpperLimit
;
186 std::unique_ptr
<ScColorScaleEntry
> mpLowerLimit
;
194 IconSet_3TrafficLights1
,
195 IconSet_3TrafficLights2
,
202 IconSet_3ColorSmilies
,
207 IconSet_4TrafficLights
,
215 struct ScIconSetMap
{
217 ScIconSetType
const eType
;
218 sal_Int32
const nElements
;
221 class SC_DLLPUBLIC ScColorFormat
: public ScFormatEntry
224 ScColorFormat(ScDocument
* pDoc
);
225 virtual ~ScColorFormat() override
;
227 const ScRangeList
& GetRange() const;
229 virtual void SetParent(ScConditionalFormat
* pParent
) override
;
231 virtual void startRendering() override
;
232 virtual void endRendering() override
;
235 std::vector
<double>& getValues() const;
237 double getMinValue() const;
238 double getMaxValue() const;
240 ScConditionalFormat
* mpParent
;
244 struct ScColorFormatCache
246 std::vector
<double> maValues
;
248 mutable std::unique_ptr
<ScColorFormatCache
> mpCache
;
251 typedef std::vector
<std::unique_ptr
<ScColorScaleEntry
>> ScColorScaleEntries
;
253 class SC_DLLPUBLIC ScColorScaleFormat final
: public ScColorFormat
256 ScColorScaleEntries maColorScales
;
258 double GetMinValue() const;
259 double GetMaxValue() const;
261 void calcMinMax(double& nMin
, double& nMax
) const;
262 double CalcValue(double nMin
, double nMax
, const ScColorScaleEntries::const_iterator
& rItr
) const;
264 ScColorScaleFormat(ScDocument
* pDoc
);
265 ScColorScaleFormat(ScDocument
* pDoc
, const ScColorScaleFormat
& rFormat
);
266 virtual ~ScColorScaleFormat() override
;
267 virtual ScColorFormat
* Clone(ScDocument
* pDoc
) const override
;
269 virtual void SetParent(ScConditionalFormat
* pParent
) override
;
271 boost::optional
<Color
> GetColor(const ScAddress
& rAddr
) const;
272 void AddEntry(ScColorScaleEntry
* pEntry
);
274 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) override
;
275 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) override
;
276 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) override
;
277 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) override
;
279 virtual Type
GetType() const override
;
280 ScColorScaleEntries::iterator
begin();
281 ScColorScaleEntries::const_iterator
begin() const;
282 ScColorScaleEntries::iterator
end();
283 ScColorScaleEntries::const_iterator
end() const;
285 ScColorScaleEntry
* GetEntry(size_t nPos
);
286 const ScColorScaleEntry
* GetEntry(size_t nPos
) const;
291 * Makes sure that the maColorScales contain at least 2 entries.
292 * Should be called when it is not sure that the format is valid.
297 class SC_DLLPUBLIC ScDataBarFormat final
: public ScColorFormat
300 ScDataBarFormat(ScDocument
* pDoc
);
301 ScDataBarFormat(ScDocument
* pDoc
, const ScDataBarFormat
& rFormat
);
302 virtual ScColorFormat
* Clone(ScDocument
* pDoc
) const override
;
304 virtual void SetParent(ScConditionalFormat
* pParent
) override
;
306 std::unique_ptr
<ScDataBarInfo
> GetDataBarInfo(const ScAddress
& rAddr
) const;
308 void SetDataBarData( ScDataBarFormatData
* pData
);
309 const ScDataBarFormatData
* GetDataBarData() const;
310 ScDataBarFormatData
* GetDataBarData();
312 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) override
;
313 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) override
;
314 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) override
;
315 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) override
;
317 virtual Type
GetType() const override
;
320 * Makes sure that the mpFormatData does not contain valid entries.
321 * Should be called when it is not sure that the format is valid.
326 double getMin(double nMin
, double nMax
) const;
327 double getMax(double nMin
, double nMax
) const;
329 std::unique_ptr
<ScDataBarFormatData
> mpFormatData
;
332 struct ScIconSetFormatData
334 ScIconSetType eIconSetType
;
337 * Specifies whether the icons should be shown in reverse order
340 typedef std::vector
<std::unique_ptr
<ScColorScaleEntry
>> Entries_t
;
343 // the std::pair points to exactly one image
344 // std..pair::second == -1 means no image
345 std::vector
<std::pair
<ScIconSetType
, sal_Int32
> > maCustomVector
;
347 ScIconSetFormatData(ScIconSetType eType
= IconSet_3Arrows
):
354 ScIconSetFormatData(ScIconSetFormatData
const&);
355 ScIconSetFormatData
& operator=(ScIconSetFormatData
const&) = delete; //TODO?
358 class SC_DLLPUBLIC ScIconSetFormat final
: public ScColorFormat
361 ScIconSetFormat(ScDocument
* pDoc
);
362 ScIconSetFormat(ScDocument
* pDoc
, const ScIconSetFormat
& rFormat
);
364 virtual ScColorFormat
* Clone(ScDocument
* pDoc
) const override
;
366 virtual void SetParent(ScConditionalFormat
* pParent
) override
;
368 std::unique_ptr
<ScIconSetInfo
> GetIconSetInfo(const ScAddress
& rAddr
) const;
370 void SetIconSetData( ScIconSetFormatData
* pData
);
371 const ScIconSetFormatData
* GetIconSetData() const;
372 ScIconSetFormatData
* GetIconSetData();
374 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) override
;
375 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) override
;
376 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) override
;
377 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) override
;
379 virtual Type
GetType() const override
;
381 static const ScIconSetMap g_IconSetMap
[];
382 static const char* getIconSetName( ScIconSetType eType
);
383 static sal_Int32
getIconSetElements( ScIconSetType eType
);
384 static OUString
getIconName(ScIconSetType eType
, sal_Int32 nIndex
);
385 static BitmapEx
& getBitmap(sc::IconSetBitmapMap
& rBitmapMap
, ScIconSetType eType
, sal_Int32 nIndex
);
387 typedef ScIconSetFormatData::Entries_t::iterator iterator
;
388 typedef ScIconSetFormatData::Entries_t::const_iterator const_iterator
;
391 const_iterator
begin() const;
393 const_iterator
end() const;
398 * Makes sure that the mpFormatData does not contain valid entries.
399 * Should be called when it is not sure that the format is valid.
405 double GetMinValue() const;
406 double GetMaxValue() const;
407 double CalcValue(double nMin
, double nMax
, const ScIconSetFormat::const_iterator
& itr
) const;
409 std::unique_ptr
<ScIconSetFormatData
> mpFormatData
;
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */