Bump version to 4.3-4
[LibreOffice.git] / sc / inc / colorscale.hxx
blob6639741dced647b58df1d4b4e9f4b7edbfc5f95b
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 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>
23 #include <vector>
25 //TODO: merge this with conditio.hxx
27 class ScDocument;
28 class ScFormulaCell;
29 class ScTokenArray;
30 struct ScDataBarInfo;
31 class BitmapEx;
32 class ScFormulaListener;
34 // don't change the order
35 // they are also used in the dialog to determine the position
36 // in the list box
37 enum ScColorScaleEntryType
39 COLORSCALE_AUTO,
40 COLORSCALE_MIN,
41 COLORSCALE_MAX,
42 COLORSCALE_PERCENTILE,
43 COLORSCALE_VALUE,
44 COLORSCALE_PERCENT,
45 COLORSCALE_FORMULA,
48 class SC_DLLPUBLIC ScColorScaleEntry
50 private:
51 double mnVal;
52 Color maColor;
53 boost::scoped_ptr<ScFormulaCell> mpCell;
54 boost::scoped_ptr<ScFormulaListener> mpListener;
55 ScColorScaleEntryType meType;
57 public:
58 ScColorScaleEntry(double nVal, const Color& rCol);
59 ScColorScaleEntry();
60 ScColorScaleEntry(const ScColorScaleEntry& rEntry);
61 ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
62 ~ScColorScaleEntry();
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;
85 namespace databar
88 enum ScAxisPosition
90 NONE,
91 AUTOMATIC,
92 MIDDLE
97 struct SC_DLLPUBLIC ScDataBarFormatData
99 ScDataBarFormatData():
100 maAxisColor(COL_BLACK),
101 mbGradient(true),
102 mbNeg(true),
103 meAxisPosition(databar::AUTOMATIC),
104 mbOnlyBar(false){}
106 ScDataBarFormatData(const ScDataBarFormatData& r):
107 maPositiveColor(r.maPositiveColor),
108 maAxisColor(r.maAxisColor),
109 mbGradient(r.mbGradient),
110 mbNeg(r.mbNeg),
111 meAxisPosition(r.meAxisPosition),
112 mbOnlyBar(r.mbOnlyBar)
114 if(r.mpNegativeColor)
115 mpNegativeColor.reset(new Color(*r.mpNegativeColor));
117 if(r.mpLowerLimit)
118 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
119 if(r.mpUpperLimit)
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
137 Color maAxisColor;
139 * Paint the bars with gradient. If this is used the default is to draw with
140 * borders.
142 * Default is true
144 bool mbGradient;
146 * Use different color for negative values. Color is specified in
147 * mpNegativeColor and defaults to 0xFF0000
149 * Default is true
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
157 * Default is false
159 databar::ScAxisPosition meAxisPosition;
162 * If TRUE we only show the bar and not the value
164 bool mbOnlyBar;
166 boost::scoped_ptr<ScColorScaleEntry> mpUpperLimit;
167 boost::scoped_ptr<ScColorScaleEntry> mpLowerLimit;
170 enum ScIconSetType
172 IconSet_3Arrows,
173 IconSet_3ArrowsGray,
174 IconSet_3Flags,
175 IconSet_3TrafficLights1,
176 IconSet_3TrafficLights2,
177 IconSet_3Signs,
178 IconSet_3Symbols,
179 IconSet_3Symbols2,
180 IconSet_3Smilies,
181 IconSet_3ColorSmilies,
182 IconSet_4Arrows,
183 IconSet_4ArrowsGray,
184 IconSet_4RedToBlack,
185 IconSet_4Rating,
186 IconSet_4TrafficLights,
187 IconSet_5Arrows,
188 IconSet_5ArrowsGray,
189 IconSet_5Ratings,
190 IconSet_5Quarters
193 struct ScIconSetMap {
194 const char* pName;
195 ScIconSetType eType;
196 sal_Int32 nElements;
199 class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
201 public:
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;
216 protected:
217 std::vector<double>& getValues() const;
219 double getMinValue() const;
220 double getMaxValue() const;
222 ScConditionalFormat* mpParent;
224 private:
226 struct ScColorFormatCache
228 std::vector<double> maValues;
230 mutable boost::scoped_ptr<ScColorFormatCache> mpCache;
233 class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
235 private:
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;
245 public:
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;
265 iterator begin();
266 const_iterator begin() const;
267 iterator end();
268 const_iterator end() const;
270 size_t size() const;
273 class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
275 public:
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;
295 private:
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;
305 bool mbShowValue;
307 * Specifies whether the icons should be shown in reverse order
309 bool mbReverse;
310 boost::ptr_vector<ScColorScaleEntry> maEntries;
312 ScIconSetFormatData():
313 eIconSetType(IconSet_3Arrows),
314 mbShowValue(true),
315 mbReverse(false)
319 class SC_DLLPUBLIC ScIconSetFormat : public ScColorFormat
321 public:
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;
348 iterator begin();
349 const_iterator begin() const;
350 iterator end();
351 const_iterator end() const;
353 private:
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;
362 #endif
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */