update emoji autocorrect entries from po-files
[LibreOffice.git] / sc / inc / colorscale.hxx
blob423d1fa8a4424294db236f0442f07fff2211a69a
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 { return maColor;}
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 { return meType;}
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 mnMinLength(0),
105 mnMaxLength(100),
106 mbOnlyBar(false){}
108 ScDataBarFormatData(const ScDataBarFormatData& r):
109 maPositiveColor(r.maPositiveColor),
110 maAxisColor(r.maAxisColor),
111 mbGradient(r.mbGradient),
112 mbNeg(r.mbNeg),
113 meAxisPosition(r.meAxisPosition),
114 mnMinLength(r.mnMinLength),
115 mnMaxLength(r.mnMaxLength),
116 mbOnlyBar(r.mbOnlyBar)
118 if(r.mpNegativeColor)
119 mpNegativeColor.reset(new Color(*r.mpNegativeColor));
121 if(r.mpLowerLimit)
122 mpLowerLimit.reset( new ScColorScaleEntry(*r.mpLowerLimit));
123 if(r.mpUpperLimit)
124 mpUpperLimit.reset( new ScColorScaleEntry(*r.mpUpperLimit));
128 * Color for all Positive Values and if mbNeg == false also for negative ones
130 Color maPositiveColor;
132 * Specifies the color for negative values. This is optional and depends on mbNeg.
134 * Default color is 0xFF0000, this value is not set
136 boost::scoped_ptr<Color> mpNegativeColor;
138 * Color of the axis if used
139 * Default color is black
141 Color maAxisColor;
143 * Paint the bars with gradient. If this is used the default is to draw with
144 * borders.
146 * Default is true
148 bool mbGradient;
150 * Use different color for negative values. Color is specified in
151 * mpNegativeColor and defaults to 0xFF0000
153 * Default is true
155 bool mbNeg; //differentiate between negative values
157 * Paint negative values into the same direction as positive values
158 * If false we will set the mid point according to the upper and lower limit and negative
159 * values are painted to the left and positive to the right
161 * Default is false
163 databar::ScAxisPosition meAxisPosition;
165 * Minimal length of a databar in percent of cell length
166 * Value has to be in the range [0, 100)
168 double mnMinLength;
170 * Maximal length of a databar in percent of cell length
171 * Value has to be in the range (0, 100]
173 double mnMaxLength;
176 * If TRUE we only show the bar and not the value
178 bool mbOnlyBar;
180 boost::scoped_ptr<ScColorScaleEntry> mpUpperLimit;
181 boost::scoped_ptr<ScColorScaleEntry> mpLowerLimit;
184 enum ScIconSetType
186 IconSet_3Arrows,
187 IconSet_3ArrowsGray,
188 IconSet_3Flags,
189 IconSet_3TrafficLights1,
190 IconSet_3TrafficLights2,
191 IconSet_3Signs,
192 IconSet_3Symbols,
193 IconSet_3Symbols2,
194 IconSet_3Smilies,
195 IconSet_3Stars,
196 IconSet_3Triangles,
197 IconSet_3ColorSmilies,
198 IconSet_4Arrows,
199 IconSet_4ArrowsGray,
200 IconSet_4RedToBlack,
201 IconSet_4Rating,
202 IconSet_4TrafficLights,
203 IconSet_5Arrows,
204 IconSet_5ArrowsGray,
205 IconSet_5Ratings,
206 IconSet_5Quarters,
207 IconSet_5Boxes
210 struct ScIconSetMap {
211 const char* pName;
212 ScIconSetType eType;
213 sal_Int32 nElements;
216 class SC_DLLPUBLIC ScColorFormat : public ScFormatEntry
218 public:
219 ScColorFormat(ScDocument* pDoc);
220 virtual ~ScColorFormat();
222 void SetRange(const ScRangeList& rList);
223 const ScRangeList& GetRange() const;
225 virtual void DataChanged(const ScRange& rRange) = 0;
226 virtual void SetParent(ScConditionalFormat* pParent) SAL_OVERRIDE;
228 virtual void startRendering() SAL_OVERRIDE;
229 virtual void endRendering() SAL_OVERRIDE;
231 virtual bool NeedsRepaint() const = 0;
233 protected:
234 std::vector<double>& getValues() const;
236 double getMinValue() const;
237 double getMaxValue() const;
239 ScConditionalFormat* mpParent;
241 private:
243 struct ScColorFormatCache
245 std::vector<double> maValues;
247 mutable boost::scoped_ptr<ScColorFormatCache> mpCache;
250 class SC_DLLPUBLIC ScColorScaleFormat : public ScColorFormat
252 private:
253 typedef boost::ptr_vector<ScColorScaleEntry> ColorScaleEntries;
254 ColorScaleEntries maColorScales;
256 double GetMinValue() const;
257 double GetMaxValue() const;
259 void calcMinMax(double& nMin, double& nMax) const;
260 bool CheckEntriesForRel(const ScRange& rRange) const;
261 double CalcValue(double nMin, double nMax, ColorScaleEntries::const_iterator& rItr) const;
262 public:
263 ScColorScaleFormat(ScDocument* pDoc);
264 ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat);
265 virtual ~ScColorScaleFormat();
266 virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const SAL_OVERRIDE;
268 Color* GetColor(const ScAddress& rAddr) const;
269 void AddEntry(ScColorScaleEntry* pEntry);
271 virtual void DataChanged(const ScRange& rRange) SAL_OVERRIDE;
272 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) SAL_OVERRIDE;
273 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) SAL_OVERRIDE;
274 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) SAL_OVERRIDE;
275 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) SAL_OVERRIDE;
277 virtual bool NeedsRepaint() const SAL_OVERRIDE;
279 virtual condformat::ScFormatEntryType GetType() const SAL_OVERRIDE;
280 typedef ColorScaleEntries::iterator iterator;
281 typedef ColorScaleEntries::const_iterator const_iterator;
282 iterator begin();
283 const_iterator begin() const;
284 iterator end();
285 const_iterator end() const;
287 ScColorScaleEntry* GetEntry(size_t nPos);
288 const ScColorScaleEntry* GetEntry(size_t nPos) const;
290 size_t size() const;
293 * Makes sure that the maColorScales contain at least 2 entries.
294 * Should be called when it is not sure that the format is valid.
296 void EnsureSize();
299 class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
301 public:
302 ScDataBarFormat(ScDocument* pDoc);
303 ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat);
304 virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const SAL_OVERRIDE;
306 ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const;
308 void SetDataBarData( ScDataBarFormatData* pData );
309 const ScDataBarFormatData* GetDataBarData() const;
310 ScDataBarFormatData* GetDataBarData();
312 virtual void DataChanged(const ScRange& rRange) SAL_OVERRIDE;
313 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) SAL_OVERRIDE;
314 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) SAL_OVERRIDE;
315 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) SAL_OVERRIDE;
316 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) SAL_OVERRIDE;
318 virtual bool NeedsRepaint() const SAL_OVERRIDE;
320 virtual condformat::ScFormatEntryType GetType() const SAL_OVERRIDE;
323 * Makes sure that the mpFormatData does not contain valid entries.
324 * Should be called when it is not sure that the format is valid.
326 void EnsureSize();
328 private:
329 double getMin(double nMin, double nMax) const;
330 double getMax(double nMin, double nMax) const;
332 boost::scoped_ptr<ScDataBarFormatData> mpFormatData;
335 struct ScIconSetFormatData
337 ScIconSetType eIconSetType;
338 bool mbShowValue;
340 * Specifies whether the icons should be shown in reverse order
342 bool mbReverse;
343 boost::ptr_vector<ScColorScaleEntry> maEntries;
344 bool mbCustom;
345 // the std::pair points to exactly one image
346 // std..pair::second == -1 means no image
347 std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector;
349 ScIconSetFormatData():
350 eIconSetType(IconSet_3Arrows),
351 mbShowValue(true),
352 mbReverse(false),
353 mbCustom(false)
357 class SC_DLLPUBLIC ScIconSetFormat : public ScColorFormat
359 public:
360 ScIconSetFormat(ScDocument* pDoc);
361 ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat);
363 virtual ScColorFormat* Clone(ScDocument* pDoc = NULL) const SAL_OVERRIDE;
365 ScIconSetInfo* GetIconSetInfo(const ScAddress& rAddr) const;
367 void SetIconSetData( ScIconSetFormatData* pData );
368 const ScIconSetFormatData* GetIconSetData() const;
369 ScIconSetFormatData* GetIconSetData();
371 virtual void DataChanged(const ScRange& rRange) SAL_OVERRIDE;
372 virtual void UpdateReference( sc::RefUpdateContext& rCxt ) SAL_OVERRIDE;
373 virtual void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) SAL_OVERRIDE;
374 virtual void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) SAL_OVERRIDE;
375 virtual void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt ) SAL_OVERRIDE;
377 virtual bool NeedsRepaint() const SAL_OVERRIDE;
379 virtual condformat::ScFormatEntryType GetType() const SAL_OVERRIDE;
381 static ScIconSetMap* getIconSetMap();
382 static BitmapEx& getBitmap( ScIconSetType eType, sal_Int32 nIndex );
384 typedef boost::ptr_vector<ScColorScaleEntry>::iterator iterator;
385 typedef boost::ptr_vector<ScColorScaleEntry>::const_iterator const_iterator;
387 iterator begin();
388 const_iterator begin() const;
389 iterator end();
390 const_iterator end() const;
392 size_t size() const;
395 * Makes sure that the mpFormatData does not contain valid entries.
396 * Should be called when it is not sure that the format is valid.
398 void EnsureSize();
400 private:
402 double GetMinValue() const;
403 double GetMaxValue() const;
404 double CalcValue(double nMin, double nMax, ScIconSetFormat::const_iterator& itr) const;
406 boost::scoped_ptr<ScIconSetFormatData> mpFormatData;
409 #endif
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */