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 { return maColor
;}
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 { return meType
;}
80 void SetType( ScColorScaleEntryType eType
);
82 bool NeedsRepaint() const;
97 struct SC_DLLPUBLIC ScDataBarFormatData
99 ScDataBarFormatData():
100 maAxisColor(COL_BLACK
),
103 meAxisPosition(databar::AUTOMATIC
),
108 ScDataBarFormatData(const ScDataBarFormatData
& r
):
109 maPositiveColor(r
.maPositiveColor
),
110 maAxisColor(r
.maAxisColor
),
111 mbGradient(r
.mbGradient
),
113 meAxisPosition(r
.meAxisPosition
),
114 mnMinLength(r
.mnMinLength
),
115 mnMaxLength(r
.mnMaxLength
),
116 mbOnlyBar(r
.mbOnlyBar
)
118 if(r
.mpNegativeColor
)
119 mpNegativeColor
.reset(new Color(*r
.mpNegativeColor
));
122 mpLowerLimit
.reset( new ScColorScaleEntry(*r
.mpLowerLimit
));
124 mpUpperLimit
.reset( new ScColorScaleEntry(*r
.mpUpperLimit
));
128 * Color for all Positive Values and if mbNeg == false also for negative ones
130 Color maPositiveColor
;
132 * Specifies the color for negative values. This is optional and depends on mbNeg.
134 * Default color is 0xFF0000, this value is not set
136 boost::scoped_ptr
<Color
> mpNegativeColor
;
138 * Color of the axis if used
139 * Default color is black
143 * Paint the bars with gradient. If this is used the default is to draw with
150 * Use different color for negative values. Color is specified in
151 * mpNegativeColor and defaults to 0xFF0000
155 bool mbNeg
; //differentiate between negative values
157 * Paint negative values into the same direction as positive values
158 * If false we will set the mid point according to the upper and lower limit and negative
159 * values are painted to the left and positive to the right
163 databar::ScAxisPosition meAxisPosition
;
165 * Minimal length of a databar in percent of cell length
166 * Value has to be in the range [0, 100)
170 * Maximal length of a databar in percent of cell length
171 * Value has to be in the range (0, 100]
176 * If TRUE we only show the bar and not the value
180 boost::scoped_ptr
<ScColorScaleEntry
> mpUpperLimit
;
181 boost::scoped_ptr
<ScColorScaleEntry
> mpLowerLimit
;
189 IconSet_3TrafficLights1
,
190 IconSet_3TrafficLights2
,
197 IconSet_3ColorSmilies
,
202 IconSet_4TrafficLights
,
210 struct ScIconSetMap
{
216 class SC_DLLPUBLIC ScColorFormat
: public ScFormatEntry
219 ScColorFormat(ScDocument
* pDoc
);
220 virtual ~ScColorFormat();
222 void SetRange(const ScRangeList
& rList
);
223 const ScRangeList
& GetRange() const;
225 virtual void DataChanged(const ScRange
& rRange
) = 0;
226 virtual void SetParent(ScConditionalFormat
* pParent
) SAL_OVERRIDE
;
228 virtual void startRendering() SAL_OVERRIDE
;
229 virtual void endRendering() SAL_OVERRIDE
;
231 virtual bool NeedsRepaint() const = 0;
234 std::vector
<double>& getValues() const;
236 double getMinValue() const;
237 double getMaxValue() const;
239 ScConditionalFormat
* mpParent
;
243 struct ScColorFormatCache
245 std::vector
<double> maValues
;
247 mutable boost::scoped_ptr
<ScColorFormatCache
> mpCache
;
250 class SC_DLLPUBLIC ScColorScaleFormat
: public ScColorFormat
253 typedef boost::ptr_vector
<ScColorScaleEntry
> ColorScaleEntries
;
254 ColorScaleEntries maColorScales
;
256 double GetMinValue() const;
257 double GetMaxValue() const;
259 void calcMinMax(double& nMin
, double& nMax
) const;
260 bool CheckEntriesForRel(const ScRange
& rRange
) const;
261 double CalcValue(double nMin
, double nMax
, ColorScaleEntries::const_iterator
& rItr
) const;
263 ScColorScaleFormat(ScDocument
* pDoc
);
264 ScColorScaleFormat(ScDocument
* pDoc
, const ScColorScaleFormat
& rFormat
);
265 virtual ~ScColorScaleFormat();
266 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const SAL_OVERRIDE
;
268 Color
* GetColor(const ScAddress
& rAddr
) const;
269 void AddEntry(ScColorScaleEntry
* pEntry
);
271 virtual void DataChanged(const ScRange
& rRange
) SAL_OVERRIDE
;
272 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) SAL_OVERRIDE
;
273 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) SAL_OVERRIDE
;
274 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) SAL_OVERRIDE
;
275 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) SAL_OVERRIDE
;
277 virtual bool NeedsRepaint() const SAL_OVERRIDE
;
279 virtual condformat::ScFormatEntryType
GetType() const SAL_OVERRIDE
;
280 typedef ColorScaleEntries::iterator iterator
;
281 typedef ColorScaleEntries::const_iterator const_iterator
;
283 const_iterator
begin() const;
285 const_iterator
end() const;
287 ScColorScaleEntry
* GetEntry(size_t nPos
);
288 const ScColorScaleEntry
* GetEntry(size_t nPos
) 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 SC_DLLPUBLIC ScDataBarFormat
: public ScColorFormat
302 ScDataBarFormat(ScDocument
* pDoc
);
303 ScDataBarFormat(ScDocument
* pDoc
, const ScDataBarFormat
& rFormat
);
304 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const SAL_OVERRIDE
;
306 ScDataBarInfo
* GetDataBarInfo(const ScAddress
& rAddr
) const;
308 void SetDataBarData( ScDataBarFormatData
* pData
);
309 const ScDataBarFormatData
* GetDataBarData() const;
310 ScDataBarFormatData
* GetDataBarData();
312 virtual void DataChanged(const ScRange
& rRange
) SAL_OVERRIDE
;
313 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) SAL_OVERRIDE
;
314 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) SAL_OVERRIDE
;
315 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) SAL_OVERRIDE
;
316 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) SAL_OVERRIDE
;
318 virtual bool NeedsRepaint() const SAL_OVERRIDE
;
320 virtual condformat::ScFormatEntryType
GetType() const SAL_OVERRIDE
;
323 * Makes sure that the mpFormatData does not contain valid entries.
324 * Should be called when it is not sure that the format is valid.
329 double getMin(double nMin
, double nMax
) const;
330 double getMax(double nMin
, double nMax
) const;
332 boost::scoped_ptr
<ScDataBarFormatData
> mpFormatData
;
335 struct ScIconSetFormatData
337 ScIconSetType eIconSetType
;
340 * Specifies whether the icons should be shown in reverse order
343 boost::ptr_vector
<ScColorScaleEntry
> maEntries
;
345 // the std::pair points to exactly one image
346 // std..pair::second == -1 means no image
347 std::vector
<std::pair
<ScIconSetType
, sal_Int32
> > maCustomVector
;
349 ScIconSetFormatData():
350 eIconSetType(IconSet_3Arrows
),
357 class SC_DLLPUBLIC ScIconSetFormat
: public ScColorFormat
360 ScIconSetFormat(ScDocument
* pDoc
);
361 ScIconSetFormat(ScDocument
* pDoc
, const ScIconSetFormat
& rFormat
);
363 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const SAL_OVERRIDE
;
365 ScIconSetInfo
* GetIconSetInfo(const ScAddress
& rAddr
) const;
367 void SetIconSetData( ScIconSetFormatData
* pData
);
368 const ScIconSetFormatData
* GetIconSetData() const;
369 ScIconSetFormatData
* GetIconSetData();
371 virtual void DataChanged(const ScRange
& rRange
) SAL_OVERRIDE
;
372 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
) SAL_OVERRIDE
;
373 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
) SAL_OVERRIDE
;
374 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
) SAL_OVERRIDE
;
375 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
) SAL_OVERRIDE
;
377 virtual bool NeedsRepaint() const SAL_OVERRIDE
;
379 virtual condformat::ScFormatEntryType
GetType() const SAL_OVERRIDE
;
381 static ScIconSetMap
* getIconSetMap();
382 static BitmapEx
& getBitmap( ScIconSetType eType
, sal_Int32 nIndex
);
384 typedef boost::ptr_vector
<ScColorScaleEntry
>::iterator iterator
;
385 typedef boost::ptr_vector
<ScColorScaleEntry
>::const_iterator const_iterator
;
388 const_iterator
begin() const;
390 const_iterator
end() const;
395 * Makes sure that the mpFormatData does not contain valid entries.
396 * Should be called when it is not sure that the format is valid.
402 double GetMinValue() const;
403 double GetMaxValue() const;
404 double CalcValue(double nMin
, double nMax
, ScIconSetFormat::const_iterator
& itr
) const;
406 boost::scoped_ptr
<ScIconSetFormatData
> mpFormatData
;
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */