update credits
[LibreOffice.git] / sc / inc / colorscale.hxx
blob5a390de6e430b616131a1914a57cdf7eb5d4ca19
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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 <vector>
22 //TODO: merge this with conditio.hxx
24 class ScDocument;
25 class ScFormulaCell;
26 class ScTokenArray;
27 struct ScDataBarInfo;
28 class BitmapEx;
30 // don't change the order
31 // they are also used in the dialog to determine the position
32 // in the list box
33 enum ScColorScaleEntryType
35 COLORSCALE_AUTO,
36 COLORSCALE_MIN,
37 COLORSCALE_MAX,
38 COLORSCALE_PERCENTILE,
39 COLORSCALE_VALUE,
40 COLORSCALE_PERCENT,
41 COLORSCALE_FORMULA,
44 class SC_DLLPUBLIC ScColorScaleEntry
46 private:
47 double mnVal;
48 Color maColor;
49 boost::scoped_ptr<ScFormulaCell> mpCell;
50 ScColorScaleEntryType meType;
52 public:
53 ScColorScaleEntry(double nVal, const Color& rCol);
54 ScColorScaleEntry();
55 ScColorScaleEntry(const ScColorScaleEntry& rEntry);
56 ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
57 ~ScColorScaleEntry();
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 );
76 namespace databar
79 enum ScAxisPosition
81 NONE,
82 AUTOMATIC,
83 MIDDLE
88 struct SC_DLLPUBLIC ScDataBarFormatData
90 ScDataBarFormatData():
91 maAxisColor(COL_BLACK),
92 mbGradient(true),
93 mbNeg(true),
94 meAxisPosition(databar::AUTOMATIC),
95 mbOnlyBar(false){}
97 ScDataBarFormatData(const ScDataBarFormatData& r):
98 maPositiveColor(r.maPositiveColor),
99 maAxisColor(r.maAxisColor),
100 mbGradient(r.mbGradient),
101 mbNeg(r.mbNeg),
102 meAxisPosition(r.meAxisPosition),
103 mbOnlyBar(r.mbOnlyBar)
105 if(r.mpNegativeColor)
106 mpNegativeColor.reset(new Color(*r.mpNegativeColor));
108 if(r.mpLowerLimit)
109 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
110 if(r.mpUpperLimit)
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
128 Color maAxisColor;
130 * Paint the bars with gradient. If this is used the default is to draw with
131 * borders.
133 * Default is true
135 bool mbGradient;
137 * Use different color for negative values. Color is specified in
138 * mpNegativeColor and defaults to 0xFF0000
140 * Default is true
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
148 * Default is false
150 databar::ScAxisPosition meAxisPosition;
153 * If TRUE we only show the bar and not the value
155 bool mbOnlyBar;
157 boost::scoped_ptr<ScColorScaleEntry> mpUpperLimit;
158 boost::scoped_ptr<ScColorScaleEntry> mpLowerLimit;
161 enum ScIconSetType
163 IconSet_3Arrows,
164 IconSet_3ArrowsGray,
165 IconSet_3Flags,
166 IconSet_3TrafficLights1,
167 IconSet_3TrafficLights2,
168 IconSet_3Signs,
169 IconSet_3Symbols,
170 IconSet_3Symbols2,
171 IconSet_4Arrows,
172 IconSet_4ArrowsGray,
173 IconSet_4RedToBlack,
174 IconSet_4Rating,
175 IconSet_4TrafficLights,
176 IconSet_5Arrows,
177 IconSet_5ArrowsGray,
178 IconSet_5Ratings,
179 IconSet_5Quarters
182 struct ScIconSetMap {
183 const char* pName;
184 ScIconSetType eType;
185 sal_Int32 nElements;
188 class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
190 public:
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();
203 protected:
204 std::vector<double>& getValues() const;
206 double getMinValue() const;
207 double getMaxValue() const;
209 ScConditionalFormat* mpParent;
211 private:
213 struct ScColorFormatCache
215 std::vector<double> maValues;
217 mutable boost::scoped_ptr<ScColorFormatCache> mpCache;
220 class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
222 private:
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;
232 public:
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;
249 iterator begin();
250 const_iterator begin() const;
251 iterator end();
252 const_iterator end() const;
254 size_t size() const;
257 class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
259 public:
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;
276 private:
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;
286 bool mbShowValue;
288 * Specifies whether the icons should be shown in reverse order
290 bool mbReverse;
291 boost::ptr_vector<ScColorScaleEntry> maEntries;
293 ScIconSetFormatData():
294 mbShowValue(true),
295 mbReverse(false) {}
298 class SC_DLLPUBLIC ScIconSetFormat : public ScColorFormat
300 public:
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;
324 iterator begin();
325 const_iterator begin() const;
326 iterator end();
327 const_iterator end() const;
329 private:
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;
338 #endif
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */