Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / colorscale.hxx
blob9dcce78d9b568c8645b753d9cc769f93b3e0f98e
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 <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 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;
86 namespace databar
89 enum ScAxisPosition
91 NONE,
92 AUTOMATIC,
93 MIDDLE
98 struct SC_DLLPUBLIC ScDataBarFormatData
100 ScDataBarFormatData():
101 maAxisColor(COL_BLACK),
102 mbGradient(true),
103 mbNeg(true),
104 meAxisPosition(databar::AUTOMATIC),
105 mbOnlyBar(false){}
107 ScDataBarFormatData(const ScDataBarFormatData& r):
108 maPositiveColor(r.maPositiveColor),
109 maAxisColor(r.maAxisColor),
110 mbGradient(r.mbGradient),
111 mbNeg(r.mbNeg),
112 meAxisPosition(r.meAxisPosition),
113 mbOnlyBar(r.mbOnlyBar)
115 if(r.mpNegativeColor)
116 mpNegativeColor.reset(new Color(*r.mpNegativeColor));
118 if(r.mpLowerLimit)
119 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
120 if(r.mpUpperLimit)
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
138 Color maAxisColor;
140 * Paint the bars with gradient. If this is used the default is to draw with
141 * borders.
143 * Default is true
145 bool mbGradient;
147 * Use different color for negative values. Color is specified in
148 * mpNegativeColor and defaults to 0xFF0000
150 * Default is true
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
158 * Default is false
160 databar::ScAxisPosition meAxisPosition;
163 * If TRUE we only show the bar and not the value
165 bool mbOnlyBar;
167 boost::scoped_ptr<ScColorScaleEntry> mpUpperLimit;
168 boost::scoped_ptr<ScColorScaleEntry> mpLowerLimit;
171 enum ScIconSetType
173 IconSet_3Arrows,
174 IconSet_3ArrowsGray,
175 IconSet_3Flags,
176 IconSet_3TrafficLights1,
177 IconSet_3TrafficLights2,
178 IconSet_3Signs,
179 IconSet_3Symbols,
180 IconSet_3Symbols2,
181 IconSet_3Smilies,
182 IconSet_3ColorSmilies,
183 IconSet_4Arrows,
184 IconSet_4ArrowsGray,
185 IconSet_4RedToBlack,
186 IconSet_4Rating,
187 IconSet_4TrafficLights,
188 IconSet_5Arrows,
189 IconSet_5ArrowsGray,
190 IconSet_5Ratings,
191 IconSet_5Quarters
194 struct ScIconSetMap {
195 const char* pName;
196 ScIconSetType eType;
197 sal_Int32 nElements;
200 class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
202 public:
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;
217 protected:
218 std::vector<double>& getValues() const;
220 double getMinValue() const;
221 double getMaxValue() const;
223 ScConditionalFormat* mpParent;
225 private:
227 struct ScColorFormatCache
229 std::vector<double> maValues;
231 mutable boost::scoped_ptr<ScColorFormatCache> mpCache;
234 class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
236 private:
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;
246 public:
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;
266 iterator begin();
267 const_iterator begin() const;
268 iterator end();
269 const_iterator end() const;
271 size_t size() const;
274 class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
276 public:
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;
296 private:
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;
306 bool mbShowValue;
308 * Specifies whether the icons should be shown in reverse order
310 bool mbReverse;
311 boost::ptr_vector<ScColorScaleEntry> maEntries;
313 ScIconSetFormatData():
314 mbShowValue(true),
315 mbReverse(false) {}
318 class SC_DLLPUBLIC ScIconSetFormat : public ScColorFormat
320 public:
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;
347 iterator begin();
348 const_iterator begin() const;
349 iterator end();
350 const_iterator end() const;
352 private:
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;
361 #endif
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */