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/.
12 #include <formula/grammar.hxx>
13 #include <tools/color.hxx>
14 #include "conditio.hxx"
15 #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 ScColorScaleEntry
46 std::unique_ptr
<ScFormulaCell
> mpCell
;
47 std::unique_ptr
<ScFormulaListener
> mpListener
;
48 ScConditionalFormat
* mpFormat
;
50 ScColorScaleEntryType meType
;
51 bool mbGreaterThanOrEqual
;
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
);
98 struct SC_DLLPUBLIC ScDataBarFormatData
100 ScDataBarFormatData():
101 maAxisColor(COL_BLACK
),
104 meAxisPosition(databar::AUTOMATIC
),
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
),
117 meAxisPosition(r
.meAxisPosition
),
118 mnMinLength(r
.mnMinLength
),
119 mnMaxLength(r
.mnMaxLength
),
120 mbOnlyBar(r
.mbOnlyBar
)
122 mxNegativeColor
= r
.mxNegativeColor
;
125 mpLowerLimit
.reset( new ScColorScaleEntry(*r
.mpLowerLimit
));
127 mpLowerLimit
.reset(new ScColorScaleEntry());
129 mpUpperLimit
.reset( new ScColorScaleEntry(*r
.mpUpperLimit
));
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
150 * Paint the bars with gradient. If this is used the default is to draw with
157 * Use different color for negative values. Color is specified in
158 * mpNegativeColor and defaults to 0xFF0000
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
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)
177 * Maximal length of a databar in percent of cell length
178 * Value has to be in the range (0, 100]
183 * If TRUE we only show the bar and not the value
187 std::unique_ptr
<ScColorScaleEntry
, o3tl::default_delete
<ScColorScaleEntry
>> mpUpperLimit
;
188 std::unique_ptr
<ScColorScaleEntry
, o3tl::default_delete
<ScColorScaleEntry
>> mpLowerLimit
;
196 IconSet_3TrafficLights1
,
197 IconSet_3TrafficLights2
,
204 IconSet_3ColorSmilies
,
209 IconSet_4TrafficLights
,
217 struct ScIconSetMap
{
223 class SAL_DLLPUBLIC_RTTI ScColorFormat
: public ScFormatEntry
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
;
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
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;
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.
299 class SAL_DLLPUBLIC_RTTI ScDataBarFormat final
: public ScColorFormat
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.
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
;
341 * Specifies whether the icons should be shown in reverse order
344 typedef std::vector
<std::unique_ptr
<ScColorScaleEntry
, o3tl::default_delete
<ScColorScaleEntry
>>> Entries_t
;
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
):
358 ScIconSetFormatData(ScIconSetFormatData
const&);
359 ScIconSetFormatData
& operator=(ScIconSetFormatData
const&) = delete; //TODO?
362 class SAL_DLLPUBLIC_RTTI ScIconSetFormat final
: public ScColorFormat
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
;
395 SC_DLLPUBLIC const_iterator
begin() const;
397 SC_DLLPUBLIC const_iterator
end() 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.
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: */