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 <boost/ptr_container/ptr_vector.hpp>
14 #include <boost/scoped_ptr.hpp>
15 #include <formula/grammar.hxx>
16 #include <tools/color.hxx>
17 #include "rangelst.hxx"
18 #include "conditio.hxx"
20 #include <svl/listener.hxx>
21 #include <svl/broadcast.hxx>
25 //TODO: merge this with conditio.hxx
32 class ScFormulaListener
;
34 // don't change the order
35 // they are also used in the dialog to determine the position
37 enum ScColorScaleEntryType
42 COLORSCALE_PERCENTILE
,
48 class SC_DLLPUBLIC ScColorScaleEntry
53 boost::scoped_ptr
<ScFormulaCell
> mpCell
;
54 boost::scoped_ptr
<ScFormulaListener
> mpListener
;
55 ScColorScaleEntryType meType
;
58 ScColorScaleEntry(double nVal
, const Color
& rCol
);
60 ScColorScaleEntry(const ScColorScaleEntry
& rEntry
);
61 ScColorScaleEntry(ScDocument
* pDoc
, const ScColorScaleEntry
& rEntry
);
64 const Color
& GetColor() const;
65 void SetColor(const Color
&);
66 double GetValue() const;
67 void SetValue(double nValue
);
68 void SetFormula(const OUString
& rFormula
, ScDocument
* pDoc
, const ScAddress
& rAddr
,
69 formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
71 void UpdateReference( sc::RefUpdateContext
& rCxt
);
72 void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
);
73 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
);
74 void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
);
76 const ScTokenArray
* GetFormula() const;
77 OUString
GetFormula( formula::FormulaGrammar::Grammar eGrammar
) const;
79 ScColorScaleEntryType
GetType() const;
80 void SetType( ScColorScaleEntryType eType
);
82 bool NeedsRepaint() const;
97 struct SC_DLLPUBLIC ScDataBarFormatData
99 ScDataBarFormatData():
100 maAxisColor(COL_BLACK
),
103 meAxisPosition(databar::AUTOMATIC
),
106 ScDataBarFormatData(const ScDataBarFormatData
& r
):
107 maPositiveColor(r
.maPositiveColor
),
108 maAxisColor(r
.maAxisColor
),
109 mbGradient(r
.mbGradient
),
111 meAxisPosition(r
.meAxisPosition
),
112 mbOnlyBar(r
.mbOnlyBar
)
114 if(r
.mpNegativeColor
)
115 mpNegativeColor
.reset(new Color(*r
.mpNegativeColor
));
118 mpLowerLimit
.reset( new ScColorScaleEntry(*r
.mpLowerLimit
));
120 mpUpperLimit
.reset( new ScColorScaleEntry(*r
.mpUpperLimit
));
124 * Color for all Positive Values and if mbNeg == false also for negative ones
126 Color maPositiveColor
;
128 * Specifies the color for negative values. This is optional and depends on mbNeg.
130 * Default color is 0xFF0000, this value is not set
132 boost::scoped_ptr
<Color
> mpNegativeColor
;
134 * Color of the axis if used
135 * Default color is black
139 * Paint the bars with gradient. If this is used the default is to draw with
146 * Use different color for negative values. Color is specified in
147 * mpNegativeColor and defaults to 0xFF0000
151 bool mbNeg
; //differentiate between negative values
153 * Paint negative values into the same direction as positive values
154 * If false we will set the mid point according to the upper and lower limit and negative
155 * values are painted to the left and positive to the right
159 databar::ScAxisPosition meAxisPosition
;
162 * If TRUE we only show the bar and not the value
166 boost::scoped_ptr
<ScColorScaleEntry
> mpUpperLimit
;
167 boost::scoped_ptr
<ScColorScaleEntry
> mpLowerLimit
;
175 IconSet_3TrafficLights1
,
176 IconSet_3TrafficLights2
,
181 IconSet_3ColorSmilies
,
186 IconSet_4TrafficLights
,
193 struct ScIconSetMap
{
199 class SC_DLLPUBLIC ScColorFormat
: public ScFormatEntry
202 ScColorFormat(ScDocument
* pDoc
);
203 virtual ~ScColorFormat();
205 void SetRange(const ScRangeList
& rList
);
206 const ScRangeList
& GetRange() const;
208 virtual void DataChanged(const ScRange
& rRange
) = 0;
209 virtual void SetParent(ScConditionalFormat
* pParent
) SAL_OVERRIDE
;
211 virtual void startRendering() SAL_OVERRIDE
;
212 virtual void endRendering() SAL_OVERRIDE
;
214 virtual bool NeedsRepaint() const = 0;
217 std::vector
<double>& getValues() const;
219 double getMinValue() const;
220 double getMaxValue() const;
222 ScConditionalFormat
* mpParent
;
226 struct ScColorFormatCache
228 std::vector
<double> maValues
;
230 mutable boost::scoped_ptr
<ScColorFormatCache
> mpCache
;
233 class SC_DLLPUBLIC ScColorScaleFormat
: public ScColorFormat
236 typedef boost::ptr_vector
<ScColorScaleEntry
> ColorScaleEntries
;
237 ColorScaleEntries maColorScales
;
239 double GetMinValue() const;
240 double GetMaxValue() const;
242 void calcMinMax(double& nMin
, double& nMax
) const;
243 bool CheckEntriesForRel(const ScRange
& rRange
) const;
244 double CalcValue(double nMin
, double nMax
, ColorScaleEntries::const_iterator
& rItr
) const;
246 ScColorScaleFormat(ScDocument
* pDoc
);
247 ScColorScaleFormat(ScDocument
* pDoc
, const ScColorScaleFormat
& rFormat
);
248 virtual ~ScColorScaleFormat();
249 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const SAL_OVERRIDE
;
251 Color
* GetColor(const ScAddress
& rAddr
) const;
252 void AddEntry(ScColorScaleEntry
* pEntry
);
254 virtual void DataChanged(const ScRange
& rRange
) SAL_OVERRIDE
;
255 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) SAL_OVERRIDE
;
256 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) SAL_OVERRIDE
;
257 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) SAL_OVERRIDE
;
258 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) SAL_OVERRIDE
;
260 virtual bool NeedsRepaint() const SAL_OVERRIDE
;
262 virtual condformat::ScFormatEntryType
GetType() const SAL_OVERRIDE
;
263 typedef ColorScaleEntries::iterator iterator
;
264 typedef ColorScaleEntries::const_iterator const_iterator
;
266 const_iterator
begin() const;
268 const_iterator
end() const;
273 class SC_DLLPUBLIC ScDataBarFormat
: public ScColorFormat
276 ScDataBarFormat(ScDocument
* pDoc
);
277 ScDataBarFormat(ScDocument
* pDoc
, const ScDataBarFormat
& rFormat
);
278 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const SAL_OVERRIDE
;
280 ScDataBarInfo
* GetDataBarInfo(const ScAddress
& rAddr
) const;
282 void SetDataBarData( ScDataBarFormatData
* pData
);
283 const ScDataBarFormatData
* GetDataBarData() const;
285 virtual void DataChanged(const ScRange
& rRange
) SAL_OVERRIDE
;
286 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) SAL_OVERRIDE
;
287 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) SAL_OVERRIDE
;
288 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) SAL_OVERRIDE
;
289 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) SAL_OVERRIDE
;
291 virtual bool NeedsRepaint() const SAL_OVERRIDE
;
293 virtual condformat::ScFormatEntryType
GetType() const SAL_OVERRIDE
;
296 double getMin(double nMin
, double nMax
) const;
297 double getMax(double nMin
, double nMax
) const;
299 boost::scoped_ptr
<ScDataBarFormatData
> mpFormatData
;
302 struct ScIconSetFormatData
304 ScIconSetType eIconSetType
;
307 * Specifies whether the icons should be shown in reverse order
310 boost::ptr_vector
<ScColorScaleEntry
> maEntries
;
312 ScIconSetFormatData():
313 eIconSetType(IconSet_3Arrows
),
319 class SC_DLLPUBLIC ScIconSetFormat
: public ScColorFormat
322 ScIconSetFormat(ScDocument
* pDoc
);
323 ScIconSetFormat(ScDocument
* pDoc
, const ScIconSetFormat
& rFormat
);
325 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const SAL_OVERRIDE
;
327 ScIconSetInfo
* GetIconSetInfo(const ScAddress
& rAddr
) const;
329 void SetIconSetData( ScIconSetFormatData
* pData
);
330 const ScIconSetFormatData
* GetIconSetData() const;
332 virtual void DataChanged(const ScRange
& rRange
) SAL_OVERRIDE
;
333 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) SAL_OVERRIDE
;
334 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) SAL_OVERRIDE
;
335 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) SAL_OVERRIDE
;
336 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) SAL_OVERRIDE
;
338 virtual bool NeedsRepaint() const SAL_OVERRIDE
;
340 virtual condformat::ScFormatEntryType
GetType() const SAL_OVERRIDE
;
342 static ScIconSetMap
* getIconSetMap();
343 static BitmapEx
& getBitmap( ScIconSetType eType
, sal_Int32 nIndex
);
345 typedef boost::ptr_vector
<ScColorScaleEntry
>::iterator iterator
;
346 typedef boost::ptr_vector
<ScColorScaleEntry
>::const_iterator const_iterator
;
349 const_iterator
begin() const;
351 const_iterator
end() const;
355 double GetMinValue() const;
356 double GetMaxValue() const;
357 double CalcValue(double nMin
, double nMax
, ScIconSetFormat::const_iterator
& itr
) const;
359 boost::scoped_ptr
<ScIconSetFormatData
> mpFormatData
;
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */