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 SC_COLORSCALE_HXX
11 #define SC_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"
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 boost::scoped_ptr
<ScFormulaCell
> mpCell
;
50 ScColorScaleEntryType meType
;
53 ScColorScaleEntry(double nVal
, const Color
& rCol
);
55 ScColorScaleEntry(const ScColorScaleEntry
& rEntry
);
56 ScColorScaleEntry(ScDocument
* pDoc
, const ScColorScaleEntry
& rEntry
);
59 const Color
& GetColor() const;
60 void SetColor(const Color
&);
61 double GetValue() const;
62 void SetValue(double nValue
);
63 void SetFormula(const OUString
& rFormula
, ScDocument
* pDoc
, const ScAddress
& rAddr
, formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
64 void UpdateMoveTab(SCTAB nOldTab
, SCTAB nNewTab
, SCTAB nTabNo
);
65 void UpdateReference( UpdateRefMode eUpdateRefMode
,
66 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
68 const ScTokenArray
* GetFormula() const;
69 OUString
GetFormula( formula::FormulaGrammar::Grammar eGrammar
) const;
71 ScColorScaleEntryType
GetType() const;
72 void SetType( ScColorScaleEntryType eType
);
88 struct SC_DLLPUBLIC ScDataBarFormatData
90 ScDataBarFormatData():
91 maAxisColor(COL_BLACK
),
94 meAxisPosition(databar::AUTOMATIC
),
97 ScDataBarFormatData(const ScDataBarFormatData
& r
):
98 maPositiveColor(r
.maPositiveColor
),
99 maAxisColor(r
.maAxisColor
),
100 mbGradient(r
.mbGradient
),
102 meAxisPosition(r
.meAxisPosition
),
103 mbOnlyBar(r
.mbOnlyBar
)
105 if(r
.mpNegativeColor
)
106 mpNegativeColor
.reset(new Color(*r
.mpNegativeColor
));
109 mpLowerLimit
.reset( new ScColorScaleEntry(*r
.mpLowerLimit
));
111 mpUpperLimit
.reset( new ScColorScaleEntry(*r
.mpUpperLimit
));
115 * Color for all Positive Values and if mbNeg == false also for negative ones
117 Color maPositiveColor
;
119 * Specifies the color for negative values. This is optional and depends on mbNeg.
121 * Default color is 0xFF0000, this value is not set
123 boost::scoped_ptr
<Color
> mpNegativeColor
;
125 * Color of the axis if used
126 * Default color is black
130 * Paint the bars with gradient. If this is used the default is to draw with
137 * Use different color for negative values. Color is specified in
138 * mpNegativeColor and defaults to 0xFF0000
142 bool mbNeg
; //differentiate between negative values
144 * Paint negative values into the same direction as positive values
145 * If false we will set the mid point according to the upper and lower limit and negative
146 * values are painted to the left and positive to the right
150 databar::ScAxisPosition meAxisPosition
;
153 * If TRUE we only show the bar and not the value
157 boost::scoped_ptr
<ScColorScaleEntry
> mpUpperLimit
;
158 boost::scoped_ptr
<ScColorScaleEntry
> mpLowerLimit
;
166 IconSet_3TrafficLights1
,
167 IconSet_3TrafficLights2
,
175 IconSet_4TrafficLights
,
182 struct ScIconSetMap
{
188 class SC_DLLPUBLIC ScColorFormat
: public ScFormatEntry
191 ScColorFormat(ScDocument
* pDoc
);
192 virtual ~ScColorFormat();
194 void SetRange(const ScRangeList
& rList
);
195 const ScRangeList
& GetRange() const;
197 virtual void DataChanged(const ScRange
& rRange
) = 0;
198 virtual void SetParent(ScConditionalFormat
* pParent
);
200 virtual void startRendering();
201 virtual void endRendering();
204 std::vector
<double>& getValues() const;
206 double getMinValue() const;
207 double getMaxValue() const;
209 ScConditionalFormat
* mpParent
;
213 struct ScColorFormatCache
215 std::vector
<double> maValues
;
217 mutable boost::scoped_ptr
<ScColorFormatCache
> mpCache
;
220 class SC_DLLPUBLIC ScColorScaleFormat
: public ScColorFormat
223 typedef boost::ptr_vector
<ScColorScaleEntry
> ColorScaleEntries
;
224 ColorScaleEntries maColorScales
;
226 double GetMinValue() const;
227 double GetMaxValue() const;
229 void calcMinMax(double& nMin
, double& nMax
) const;
230 bool CheckEntriesForRel(const ScRange
& rRange
) const;
231 double CalcValue(double nMin
, double nMax
, ColorScaleEntries::const_iterator
& rItr
) const;
233 ScColorScaleFormat(ScDocument
* pDoc
);
234 ScColorScaleFormat(ScDocument
* pDoc
, const ScColorScaleFormat
& rFormat
);
235 virtual ~ScColorScaleFormat();
236 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const;
238 Color
* GetColor(const ScAddress
& rAddr
) const;
239 void AddEntry(ScColorScaleEntry
* pEntry
);
241 virtual void DataChanged(const ScRange
& rRange
);
242 virtual void UpdateMoveTab(SCTAB nOldTab
, SCTAB nNewTab
);
243 virtual void UpdateReference( UpdateRefMode eUpdateRefMode
,
244 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
246 virtual condformat::ScFormatEntryType
GetType() const;
247 typedef ColorScaleEntries::iterator iterator
;
248 typedef ColorScaleEntries::const_iterator const_iterator
;
250 const_iterator
begin() const;
252 const_iterator
end() const;
257 class SC_DLLPUBLIC ScDataBarFormat
: public ScColorFormat
260 ScDataBarFormat(ScDocument
* pDoc
);
261 ScDataBarFormat(ScDocument
* pDoc
, const ScDataBarFormat
& rFormat
);
262 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const;
264 ScDataBarInfo
* GetDataBarInfo(const ScAddress
& rAddr
) const;
266 void SetDataBarData( ScDataBarFormatData
* pData
);
267 const ScDataBarFormatData
* GetDataBarData() const;
269 virtual void DataChanged(const ScRange
& rRange
);
270 virtual void UpdateMoveTab(SCTAB nOldTab
, SCTAB nNewTab
);
271 virtual void UpdateReference( UpdateRefMode eUpdateRefMode
,
272 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
274 virtual condformat::ScFormatEntryType
GetType() const;
277 double getMin(double nMin
, double nMax
) const;
278 double getMax(double nMin
, double nMax
) const;
280 boost::scoped_ptr
<ScDataBarFormatData
> mpFormatData
;
283 struct ScIconSetFormatData
285 ScIconSetType eIconSetType
;
288 * Specifies whether the icons should be shown in reverse order
291 boost::ptr_vector
<ScColorScaleEntry
> maEntries
;
293 ScIconSetFormatData():
298 class SC_DLLPUBLIC ScIconSetFormat
: public ScColorFormat
301 ScIconSetFormat(ScDocument
* pDoc
);
302 ScIconSetFormat(ScDocument
* pDoc
, const ScIconSetFormat
& rFormat
);
304 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const;
306 ScIconSetInfo
* GetIconSetInfo(const ScAddress
& rAddr
) const;
308 void SetIconSetData( ScIconSetFormatData
* pData
);
309 const ScIconSetFormatData
* GetIconSetData() const;
311 virtual void DataChanged(const ScRange
& rRange
);
312 virtual void UpdateMoveTab(SCTAB nOldTab
, SCTAB nNewTab
);
313 virtual void UpdateReference( UpdateRefMode eUpdateRefMode
,
314 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
316 virtual condformat::ScFormatEntryType
GetType() const;
318 static ScIconSetMap
* getIconSetMap();
319 static BitmapEx
& getBitmap( ScIconSetType eType
, sal_Int32 nIndex
);
321 typedef boost::ptr_vector
<ScColorScaleEntry
>::iterator iterator
;
322 typedef boost::ptr_vector
<ScColorScaleEntry
>::const_iterator const_iterator
;
325 const_iterator
begin() const;
327 const_iterator
end() const;
331 double GetMinValue() const;
332 double GetMaxValue() const;
333 double CalcValue(double nMin
, double nMax
, ScIconSetFormat::const_iterator
& itr
) const;
335 boost::scoped_ptr
<ScIconSetFormatData
> mpFormatData
;
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */