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"
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 UpdateMoveTab(SCTAB nOldTab
, SCTAB nNewTab
, SCTAB nTabNo
);
72 void UpdateReference( sc::RefUpdateContext
& rCxt
);
73 void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
);
74 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
);
75 void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
);
77 const ScTokenArray
* GetFormula() const;
78 OUString
GetFormula( formula::FormulaGrammar::Grammar eGrammar
) const;
80 ScColorScaleEntryType
GetType() const;
81 void SetType( ScColorScaleEntryType eType
);
83 bool NeedsRepaint() const;
98 struct SC_DLLPUBLIC ScDataBarFormatData
100 ScDataBarFormatData():
101 maAxisColor(COL_BLACK
),
104 meAxisPosition(databar::AUTOMATIC
),
107 ScDataBarFormatData(const ScDataBarFormatData
& r
):
108 maPositiveColor(r
.maPositiveColor
),
109 maAxisColor(r
.maAxisColor
),
110 mbGradient(r
.mbGradient
),
112 meAxisPosition(r
.meAxisPosition
),
113 mbOnlyBar(r
.mbOnlyBar
)
115 if(r
.mpNegativeColor
)
116 mpNegativeColor
.reset(new Color(*r
.mpNegativeColor
));
119 mpLowerLimit
.reset( new ScColorScaleEntry(*r
.mpLowerLimit
));
121 mpUpperLimit
.reset( new ScColorScaleEntry(*r
.mpUpperLimit
));
125 * Color for all Positive Values and if mbNeg == false also for negative ones
127 Color maPositiveColor
;
129 * Specifies the color for negative values. This is optional and depends on mbNeg.
131 * Default color is 0xFF0000, this value is not set
133 boost::scoped_ptr
<Color
> mpNegativeColor
;
135 * Color of the axis if used
136 * Default color is black
140 * Paint the bars with gradient. If this is used the default is to draw with
147 * Use different color for negative values. Color is specified in
148 * mpNegativeColor and defaults to 0xFF0000
152 bool mbNeg
; //differentiate between negative values
154 * Paint negative values into the same direction as positive values
155 * If false we will set the mid point according to the upper and lower limit and negative
156 * values are painted to the left and positive to the right
160 databar::ScAxisPosition meAxisPosition
;
163 * If TRUE we only show the bar and not the value
167 boost::scoped_ptr
<ScColorScaleEntry
> mpUpperLimit
;
168 boost::scoped_ptr
<ScColorScaleEntry
> mpLowerLimit
;
176 IconSet_3TrafficLights1
,
177 IconSet_3TrafficLights2
,
182 IconSet_3ColorSmilies
,
187 IconSet_4TrafficLights
,
194 struct ScIconSetMap
{
200 class SC_DLLPUBLIC ScColorFormat
: public ScFormatEntry
203 ScColorFormat(ScDocument
* pDoc
);
204 virtual ~ScColorFormat();
206 void SetRange(const ScRangeList
& rList
);
207 const ScRangeList
& GetRange() const;
209 virtual void DataChanged(const ScRange
& rRange
) = 0;
210 virtual void SetParent(ScConditionalFormat
* pParent
);
212 virtual void startRendering();
213 virtual void endRendering();
215 virtual bool NeedsRepaint() const = 0;
218 std::vector
<double>& getValues() const;
220 double getMinValue() const;
221 double getMaxValue() const;
223 ScConditionalFormat
* mpParent
;
227 struct ScColorFormatCache
229 std::vector
<double> maValues
;
231 mutable boost::scoped_ptr
<ScColorFormatCache
> mpCache
;
234 class SC_DLLPUBLIC ScColorScaleFormat
: public ScColorFormat
237 typedef boost::ptr_vector
<ScColorScaleEntry
> ColorScaleEntries
;
238 ColorScaleEntries maColorScales
;
240 double GetMinValue() const;
241 double GetMaxValue() const;
243 void calcMinMax(double& nMin
, double& nMax
) const;
244 bool CheckEntriesForRel(const ScRange
& rRange
) const;
245 double CalcValue(double nMin
, double nMax
, ColorScaleEntries::const_iterator
& rItr
) const;
247 ScColorScaleFormat(ScDocument
* pDoc
);
248 ScColorScaleFormat(ScDocument
* pDoc
, const ScColorScaleFormat
& rFormat
);
249 virtual ~ScColorScaleFormat();
250 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const;
252 Color
* GetColor(const ScAddress
& rAddr
) const;
253 void AddEntry(ScColorScaleEntry
* pEntry
);
255 virtual void DataChanged(const ScRange
& rRange
);
256 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
);
257 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
);
258 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
);
259 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
);
261 virtual bool NeedsRepaint() const;
263 virtual condformat::ScFormatEntryType
GetType() const;
264 typedef ColorScaleEntries::iterator iterator
;
265 typedef ColorScaleEntries::const_iterator const_iterator
;
267 const_iterator
begin() const;
269 const_iterator
end() const;
274 class SC_DLLPUBLIC ScDataBarFormat
: public ScColorFormat
277 ScDataBarFormat(ScDocument
* pDoc
);
278 ScDataBarFormat(ScDocument
* pDoc
, const ScDataBarFormat
& rFormat
);
279 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const;
281 ScDataBarInfo
* GetDataBarInfo(const ScAddress
& rAddr
) const;
283 void SetDataBarData( ScDataBarFormatData
* pData
);
284 const ScDataBarFormatData
* GetDataBarData() const;
286 virtual void DataChanged(const ScRange
& rRange
);
287 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
);
288 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
);
289 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
);
290 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
);
292 virtual bool NeedsRepaint() const;
294 virtual condformat::ScFormatEntryType
GetType() const;
297 double getMin(double nMin
, double nMax
) const;
298 double getMax(double nMin
, double nMax
) const;
300 boost::scoped_ptr
<ScDataBarFormatData
> mpFormatData
;
303 struct ScIconSetFormatData
305 ScIconSetType eIconSetType
;
308 * Specifies whether the icons should be shown in reverse order
311 boost::ptr_vector
<ScColorScaleEntry
> maEntries
;
313 ScIconSetFormatData():
318 class SC_DLLPUBLIC ScIconSetFormat
: public ScColorFormat
321 ScIconSetFormat(ScDocument
* pDoc
);
322 ScIconSetFormat(ScDocument
* pDoc
, const ScIconSetFormat
& rFormat
);
324 virtual ScColorFormat
* Clone(ScDocument
* pDoc
= NULL
) const;
326 ScIconSetInfo
* GetIconSetInfo(const ScAddress
& rAddr
) const;
328 void SetIconSetData( ScIconSetFormatData
* pData
);
329 const ScIconSetFormatData
* GetIconSetData() const;
331 virtual void DataChanged(const ScRange
& rRange
);
332 virtual void UpdateReference( sc::RefUpdateContext
& rCxt
);
333 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
);
334 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
);
335 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
);
337 virtual bool NeedsRepaint() const;
339 virtual condformat::ScFormatEntryType
GetType() const;
341 static ScIconSetMap
* getIconSetMap();
342 static BitmapEx
& getBitmap( ScIconSetType eType
, sal_Int32 nIndex
);
344 typedef boost::ptr_vector
<ScColorScaleEntry
>::iterator iterator
;
345 typedef boost::ptr_vector
<ScColorScaleEntry
>::const_iterator const_iterator
;
348 const_iterator
begin() const;
350 const_iterator
end() const;
354 double GetMinValue() const;
355 double GetMaxValue() const;
356 double CalcValue(double nMin
, double nMax
, ScIconSetFormat::const_iterator
& itr
) const;
358 boost::scoped_ptr
<ScIconSetFormatData
> mpFormatData
;
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */