LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/data - colorscale.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 502 0.2 %
Date: 2012-12-17 Functions: 2 88 2.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
      17             :  *
      18             :  * All Rights Reserved.
      19             :  *
      20             :  * For minor contributions see the git repository.
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : #include "colorscale.hxx"
      30             : #include "document.hxx"
      31             : #include "cell.hxx"
      32             : #include "fillinfo.hxx"
      33             : #include "iconsets.hrc"
      34             : #include "scresid.hxx"
      35             : #if DUMP_FORMAT_INFO
      36             : #include <iostream>
      37             : #endif
      38             : 
      39             : #include <algorithm>
      40             : 
      41           0 : ScColorScaleEntry::ScColorScaleEntry():
      42             :     mnVal(0),
      43             :     mpCell(NULL),
      44           0 :     meType(COLORSCALE_VALUE)
      45             : {
      46           0 : }
      47             : 
      48           0 : ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol):
      49             :     mnVal(nVal),
      50             :     maColor(rCol),
      51             :     mpCell(NULL),
      52           0 :     meType(COLORSCALE_VALUE)
      53             : {
      54           0 : }
      55             : 
      56           0 : ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
      57             :     mnVal(rEntry.mnVal),
      58             :     maColor(rEntry.maColor),
      59             :     mpCell(),
      60           0 :     meType(rEntry.meType)
      61             : {
      62           0 : }
      63             : 
      64           0 : ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry):
      65             :     mnVal(rEntry.mnVal),
      66             :     maColor(rEntry.maColor),
      67             :     mpCell(),
      68           0 :     meType(rEntry.meType)
      69             : {
      70           0 :     if(rEntry.mpCell)
      71             :     {
      72           0 :         mpCell.reset(static_cast<ScFormulaCell*>(rEntry.mpCell->Clone(*pDoc, SC_CLONECELL_NOMAKEABS_EXTERNAL)));
      73           0 :         mpCell->StartListeningTo( pDoc );
      74             :     }
      75           0 : }
      76             : 
      77           0 : ScColorScaleEntry::~ScColorScaleEntry()
      78             : {
      79           0 : }
      80             : 
      81           0 : void ScColorScaleEntry::SetFormula( const rtl::OUString& rFormula, ScDocument* pDoc, const ScAddress& rAddr, formula::FormulaGrammar::Grammar eGrammar )
      82             : {
      83           0 :     mpCell.reset(new ScFormulaCell( pDoc, rAddr, rFormula, eGrammar ));
      84           0 :     mpCell->StartListeningTo( pDoc );
      85           0 : }
      86             : 
      87           0 : const ScTokenArray* ScColorScaleEntry::GetFormula() const
      88             : {
      89           0 :     if(mpCell)
      90             :     {
      91           0 :         return mpCell->GetCode();
      92             :     }
      93             : 
      94           0 :     return NULL;
      95             : }
      96             : 
      97           0 : rtl::OUString ScColorScaleEntry::GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const
      98             : {
      99           0 :     rtl::OUString aFormula;
     100           0 :     if(mpCell)
     101             :     {
     102           0 :         mpCell->GetFormula(aFormula, eGrammar);
     103             :     }
     104             : 
     105           0 :     return aFormula;
     106             : }
     107             : 
     108           0 : double ScColorScaleEntry::GetValue() const
     109             : {
     110           0 :     if(mpCell)
     111             :     {
     112           0 :         mpCell->Interpret();
     113           0 :         if(mpCell->IsValue())
     114           0 :             return mpCell->GetValue();
     115             : 
     116           0 :         return std::numeric_limits<double>::max();
     117             :     }
     118             : 
     119           0 :     return mnVal;
     120             : }
     121             : 
     122           0 : void ScColorScaleEntry::SetValue(double nValue)
     123             : {
     124           0 :     mnVal = nValue;
     125           0 : }
     126             : 
     127           0 : void ScColorScaleEntry::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab, SCTAB nTabNo )
     128             : {
     129           0 :     if(mpCell)
     130             :     {
     131           0 :         mpCell->UpdateMoveTab( nOldTab, nNewTab, nTabNo );
     132             :     }
     133           0 : }
     134             : 
     135           0 : void ScColorScaleEntry::UpdateReference( UpdateRefMode eUpdateRefMode,
     136             :             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
     137             : {
     138           0 :     if(mpCell)
     139             :     {
     140           0 :         mpCell->UpdateReference( eUpdateRefMode, rRange, nDx, nDy, nDz );
     141             :     }
     142           0 : }
     143             : 
     144           0 : const Color& ScColorScaleEntry::GetColor() const
     145             : {
     146           0 :     return maColor;
     147             : }
     148             : 
     149           0 : void ScColorScaleEntry::SetColor(const Color& rColor)
     150             : {
     151           0 :     maColor = rColor;
     152           0 : }
     153             : 
     154             : #if DUMP_FORMAT_INFO
     155             : 
     156           0 : void ScColorScaleEntry::dumpInfo(rtl::OUStringBuffer& rBuf) const
     157             : {
     158           0 :     rBuf.append("Color Scale Entry\n");
     159           0 :     rBuf.append("Type: ");
     160           0 :     switch(meType)
     161             :     {
     162             :         case COLORSCALE_VALUE:
     163           0 :             rBuf.append( "Value\n" );
     164           0 :             break;
     165             :         case COLORSCALE_MIN:
     166           0 :             rBuf.append( "Min\n" );
     167           0 :             break;
     168             :         case COLORSCALE_MAX:
     169           0 :             rBuf.append( "Max\n" );
     170           0 :             break;
     171             :         case COLORSCALE_PERCENT:
     172           0 :             rBuf.append( "Percent\n" );
     173           0 :             break;
     174             :         case COLORSCALE_PERCENTILE:
     175           0 :             rBuf.append( "Percentile\n" );
     176           0 :             break;
     177             :         case COLORSCALE_FORMULA:
     178           0 :             rBuf.append( "Formual\n" );
     179           0 :             break;
     180             :         default:
     181           0 :             rBuf.append( "Unsupported Type\n" );
     182             :     }
     183           0 :     rBuf.append( "Color: " ).append( (sal_Int32)maColor.GetRed() ).append( "," ).append( (sal_Int32)maColor.GetGreen() ).append( "," ).append( (sal_Int32)maColor.GetBlue() ).append( "\n" );
     184           0 :     if(meType == COLORSCALE_FORMULA)
     185           0 :         rBuf.append( "Formula: " ).append( GetFormula( formula::FormulaGrammar::GRAM_DEFAULT ) ).append("\n");
     186           0 :     else if( meType != COLORSCALE_MIN && meType != COLORSCALE_MAX )
     187           0 :         rBuf.append( "Value: " ).append( mnVal ).append( "\n" );
     188           0 : }
     189             : 
     190             : #endif
     191             : 
     192           0 : ScColorFormat::ScColorFormat(ScDocument* pDoc):
     193           0 :     ScFormatEntry(pDoc)
     194             : {
     195           0 : }
     196             : 
     197           0 : ScColorFormat::~ScColorFormat()
     198             : {
     199           0 : }
     200             : 
     201           0 : void ScColorFormat::SetParent( ScConditionalFormat* pParent )
     202             : {
     203           0 :     mpParent = pParent;
     204           0 : }
     205             : 
     206           0 : ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc):
     207           0 :     ScColorFormat(pDoc)
     208             : {
     209           0 : }
     210             : 
     211           0 : ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc, const ScColorScaleFormat& rFormat):
     212           0 :     ScColorFormat(pDoc)
     213             : {
     214           0 :     for(const_iterator itr = rFormat.begin(); itr != rFormat.end(); ++itr)
     215             :     {
     216           0 :         maColorScales.push_back(new ScColorScaleEntry(pDoc, *itr));
     217             :     }
     218           0 : }
     219             : 
     220           0 : ScColorFormat* ScColorScaleFormat::Clone(ScDocument* pDoc) const
     221             : {
     222           0 :     return new ScColorScaleFormat(pDoc, *this);
     223             : }
     224             : 
     225           0 : ScColorScaleFormat::~ScColorScaleFormat()
     226             : {
     227           0 : }
     228             : 
     229           0 : void ScColorScaleFormat::AddEntry( ScColorScaleEntry* pEntry )
     230             : {
     231           0 :     maColorScales.push_back( pEntry );
     232           0 : }
     233             : 
     234           0 : void ScColorScaleEntry::SetType( ScColorScaleEntryType eType )
     235             : {
     236           0 :     meType = eType;
     237           0 :     if(eType != COLORSCALE_FORMULA)
     238           0 :         mpCell.reset();
     239           0 : }
     240             : 
     241           0 : ScColorScaleEntryType ScColorScaleEntry::GetType() const
     242             : {
     243           0 :     return meType;
     244             : }
     245             : 
     246           0 : double ScColorScaleFormat::GetMinValue() const
     247             : {
     248           0 :     const_iterator itr = maColorScales.begin();
     249             : 
     250           0 :     if(itr->GetType() == COLORSCALE_VALUE || itr->GetType() == COLORSCALE_FORMULA)
     251           0 :         return itr->GetValue();
     252             :     else
     253             :     {
     254           0 :         return getMinValue();
     255             :     }
     256             : }
     257             : 
     258           0 : double ScColorScaleFormat::GetMaxValue() const
     259             : {
     260           0 :     ColorScaleEntries::const_reverse_iterator itr = maColorScales.rbegin();
     261             : 
     262           0 :     if(itr->GetType() == COLORSCALE_VALUE || itr->GetType() == COLORSCALE_FORMULA)
     263           0 :         return itr->GetValue();
     264             :     else
     265             :     {
     266           0 :         return getMaxValue();
     267             :     }
     268             : }
     269             : 
     270           0 : void ScColorScaleFormat::calcMinMax(double& rMin, double& rMax) const
     271             : {
     272           0 :     rMin = GetMinValue();
     273           0 :     rMax = GetMaxValue();
     274           0 : }
     275             : 
     276           0 : const ScRangeList& ScColorFormat::GetRange() const
     277             : {
     278           0 :     return mpParent->GetRange();
     279             : }
     280             : 
     281           0 : std::vector<double>& ScColorFormat::getValues() const
     282             : {
     283           0 :     if(!mpCache)
     284             :     {
     285           0 :         mpCache.reset(new ScColorFormatCache);
     286           0 :         std::vector<double>& rValues = mpCache->maValues;
     287             : 
     288           0 :         size_t n = GetRange().size();
     289           0 :         const ScRangeList& aRanges = GetRange();
     290           0 :         for(size_t i = 0; i < n; ++i)
     291             :         {
     292           0 :             const ScRange* pRange = aRanges[i];
     293           0 :             SCTAB nTab = pRange->aStart.Tab();
     294           0 :             for(SCCOL nCol = pRange->aStart.Col(); nCol <= pRange->aEnd.Col(); ++nCol)
     295             :             {
     296           0 :                 for(SCCOL nRow = pRange->aStart.Row(); nRow <= pRange->aEnd.Row(); ++nRow)
     297             :                 {
     298           0 :                     ScAddress aAddr(nCol, nRow, nTab);
     299           0 :                     CellType eType = mpDoc->GetCellType(aAddr);
     300           0 :                     if(eType == CELLTYPE_VALUE)
     301             :                     {
     302           0 :                         double aVal = mpDoc->GetValue(nCol, nRow, nTab);
     303           0 :                         rValues.push_back(aVal);
     304             :                     }
     305           0 :                     else if(eType == CELLTYPE_FORMULA)
     306             :                     {
     307           0 :                         if(static_cast<ScFormulaCell*>(mpDoc->GetCell(aAddr))->IsValue())
     308             :                         {
     309           0 :                             double aVal = mpDoc->GetValue(nCol, nRow, nTab);
     310           0 :                             rValues.push_back(aVal);
     311             :                         }
     312             :                     }
     313             :                 }
     314             :             }
     315             :         }
     316             : 
     317           0 :         std::sort(rValues.begin(), rValues.end());
     318             :     }
     319             : 
     320           0 :     return mpCache->maValues;
     321             : }
     322             : 
     323           0 : double ScColorFormat::getMinValue() const
     324             : {
     325           0 :     std::vector<double>& rValues = getValues();
     326           0 :     if(rValues.empty())
     327           0 :         return 0;
     328           0 :     return rValues[0];
     329             : }
     330             : 
     331           0 : double ScColorFormat::getMaxValue() const
     332             : {
     333           0 :     std::vector<double>& rValues = getValues();
     334           0 :     if(rValues.empty())
     335           0 :         return 0;
     336           0 :     return rValues[rValues.size()-1];
     337             : }
     338             : 
     339           0 : void ScColorFormat::startRendering()
     340             : {
     341           0 :     mpCache.reset();
     342           0 : }
     343             : 
     344           0 : void ScColorFormat::endRendering()
     345             : {
     346           0 :     mpCache.reset();
     347           0 : }
     348             : 
     349             : namespace {
     350             : 
     351           0 : sal_uInt8 GetColorValue( double nVal, double nVal1, sal_uInt8 nColVal1, double nVal2, sal_uInt8 nColVal2 )
     352             : {
     353           0 :     if (nVal <= nVal1)
     354           0 :         return nColVal1;
     355             : 
     356           0 :     if (nVal >= nVal2)
     357           0 :         return nColVal2;
     358             : 
     359           0 :     sal_uInt8 nColVal = static_cast<sal_uInt8>((nVal - nVal1)/(nVal2-nVal1)*(nColVal2-nColVal1))+nColVal1;
     360           0 :     return nColVal;
     361             : }
     362             : 
     363           0 : Color CalcColor( double nVal, double nVal1, const Color& rCol1, double nVal2, const Color& rCol2)
     364             : {
     365           0 :     sal_uInt8 nColRed = GetColorValue(nVal, nVal1, rCol1.GetRed(), nVal2, rCol2.GetRed());
     366           0 :     sal_uInt8 nColBlue = GetColorValue(nVal, nVal1, rCol1.GetBlue(), nVal2, rCol2.GetBlue());
     367           0 :     sal_uInt8 nColGreen = GetColorValue(nVal, nVal1, rCol1.GetGreen(), nVal2, rCol2.GetGreen());
     368             : 
     369           0 :     return Color(nColRed, nColGreen, nColBlue);
     370             : }
     371             : 
     372             : /**
     373             :  * @param rVector sorted vector of the array
     374             :  * @param fPercentile percentile
     375             :  */
     376           0 : double GetPercentile( const std::vector<double>& rArray, double fPercentile )
     377             : {
     378           0 :     size_t nSize = rArray.size();
     379           0 :     size_t nIndex = (size_t)::rtl::math::approxFloor( fPercentile * (nSize-1));
     380           0 :     double fDiff = fPercentile * (nSize-1) - ::rtl::math::approxFloor( fPercentile * (nSize-1));
     381           0 :     std::vector<double>::const_iterator iter = rArray.begin() + nIndex;
     382           0 :     if (fDiff == 0.0)
     383           0 :         return *iter;
     384             :     else
     385             :     {
     386           0 :         double fVal = *iter;
     387           0 :         iter = rArray.begin() + nIndex+1;
     388           0 :         return fVal + fDiff * (*iter - fVal);
     389             :     }
     390             : }
     391             : 
     392             : }
     393             : 
     394           0 : double ScColorScaleFormat::CalcValue(double nMin, double nMax, ScColorScaleFormat::const_iterator& itr) const
     395             : {
     396           0 :     switch(itr->GetType())
     397             :     {
     398             :         case COLORSCALE_PERCENT:
     399           0 :             return nMin + (nMax-nMin)*(itr->GetValue()/100);
     400             :         case COLORSCALE_MIN:
     401           0 :             return nMin;
     402             :         case COLORSCALE_MAX:
     403           0 :             return nMax;
     404             :         case COLORSCALE_PERCENTILE:
     405             :         {
     406           0 :             std::vector<double>& rValues = getValues();
     407           0 :             if(rValues.size() == 1)
     408           0 :                 return rValues[0];
     409             :             else
     410             :             {
     411           0 :                 double fPercentile = itr->GetValue()/100.0;
     412           0 :                 return GetPercentile(rValues, fPercentile);
     413             :             }
     414             :         }
     415             : 
     416             :         default:
     417           0 :         break;
     418             :     }
     419             : 
     420           0 :     return itr->GetValue();
     421             : }
     422             : 
     423           0 : Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const
     424             : {
     425           0 :     CellType eCellType = mpDoc->GetCellType(rAddr);
     426           0 :     if(eCellType != CELLTYPE_VALUE && eCellType != CELLTYPE_FORMULA)
     427           0 :         return NULL;
     428             : 
     429           0 :     if (eCellType == CELLTYPE_FORMULA)
     430             :     {
     431           0 :         if(!static_cast<ScFormulaCell*>(mpDoc->GetCell(rAddr))->IsValue())
     432           0 :             return NULL;
     433             :     }
     434             : 
     435             :     // now we have for sure a value
     436           0 :     double nVal = mpDoc->GetValue(rAddr);
     437             : 
     438           0 :     if (maColorScales.size() < 2)
     439           0 :         return NULL;
     440             : 
     441           0 :     double nMin = std::numeric_limits<double>::max();
     442           0 :     double nMax = std::numeric_limits<double>::min();
     443           0 :     calcMinMax(nMin, nMax);
     444             : 
     445             :     // this check is for safety
     446           0 :     if(nMin >= nMax)
     447           0 :         return NULL;
     448             : 
     449           0 :     const_iterator itr = begin();
     450           0 :     double nValMin = CalcValue(nMin, nMax, itr);
     451           0 :     Color rColMin = itr->GetColor();
     452           0 :     ++itr;
     453           0 :     double nValMax = CalcValue(nMin, nMax, itr);
     454           0 :     Color rColMax = itr->GetColor();
     455             : 
     456           0 :     ++itr;
     457           0 :     while(itr != end() && nVal > nValMax)
     458             :     {
     459           0 :         rColMin = rColMax;
     460           0 :         nValMin = nValMax;
     461           0 :         rColMax = itr->GetColor();
     462           0 :         nValMax = CalcValue(nMin, nMax, itr);
     463           0 :         ++itr;
     464             :     }
     465             : 
     466           0 :     Color aColor = CalcColor(nVal, nValMin, rColMin, nValMax, rColMax);
     467             : 
     468           0 :     return new Color(aColor);
     469             : }
     470             : 
     471             : #if DUMP_FORMAT_INFO
     472           0 : void ScColorScaleFormat::dumpInfo(rtl::OUStringBuffer& rBuf) const
     473             : {
     474           0 :     rBuf.append("Color Scale with ").append(static_cast<sal_Int32>(size())).append(" entries\n");
     475           0 :     for(const_iterator itr = begin(); itr != end(); ++itr)
     476             :     {
     477           0 :         itr->dumpInfo(rBuf);
     478             :     }
     479             : 
     480           0 :     const ScRangeList& rRange = GetRange();
     481           0 :     size_t n = rRange.size();
     482           0 :     for(size_t i = 0; i < n; ++i)
     483             :     {
     484           0 :         const ScRange* pRange = rRange[i];
     485           0 :         SCTAB nTab = pRange->aStart.Tab();
     486           0 :         for( SCCOL nCol = pRange->aStart.Col(), nEndCol = pRange->aEnd.Col(); nCol <= nEndCol; ++nCol)
     487             :         {
     488           0 :             for( SCROW nRow = pRange->aStart.Row(), nEndRow = pRange->aEnd.Row(); nRow <= nEndRow; ++nRow)
     489             :             {
     490           0 :                 boost::scoped_ptr<Color> pColor( GetColor(ScAddress(nCol, nRow, nTab)) );
     491           0 :                 rBuf.append((sal_Int32)nCol).append(",").append(nRow).append(",").append((sal_Int32)nTab).append(",");
     492           0 :                 rBuf.append(((sal_Int32)pColor->GetRed())).append(",").append(((sal_Int32)pColor->GetGreen())).append(",").append(((sal_Int32)pColor->GetBlue())).append("\n");
     493           0 :             }
     494             :         }
     495             :     }
     496           0 : }
     497             : #endif
     498             : 
     499           0 : void ScColorScaleFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
     500             : {
     501           0 :     SCTAB nThisTab = GetRange().front()->aStart.Tab();
     502           0 :     for(iterator itr = begin(); itr != end(); ++itr)
     503             :     {
     504           0 :         itr->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
     505             :     }
     506           0 : }
     507             : 
     508           0 : void ScColorScaleFormat::UpdateReference( UpdateRefMode eUpdateRefMode,
     509             :             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
     510             : {
     511           0 :     for(iterator itr = begin(); itr != end(); ++itr)
     512             :     {
     513           0 :         itr->UpdateReference(eUpdateRefMode, rRange, nDx, nDy, nDz);
     514             :     }
     515           0 : }
     516             : 
     517           0 : bool ScColorScaleFormat::CheckEntriesForRel(const ScRange& rRange) const
     518             : {
     519           0 :     bool bNeedUpdate = false;
     520           0 :     for(const_iterator itr = begin(); itr != end(); ++itr)
     521             :     {
     522           0 :         ScColorScaleEntryType eType = itr->GetType();
     523           0 :         switch(eType)
     524             :         {
     525             :             case COLORSCALE_MIN:
     526             :             case COLORSCALE_MAX:
     527           0 :                 bNeedUpdate = true;
     528           0 :                 break;
     529             :             case COLORSCALE_FORMULA:
     530           0 :                 return true;
     531             :             default:
     532           0 :                 break;
     533             :         }
     534             :     }
     535             : 
     536             :     // TODO: check also if the changed value is the new min/max
     537             :     // or has been the old min/max value
     538           0 :     bNeedUpdate = bNeedUpdate && GetRange().Intersects(rRange);
     539           0 :     return bNeedUpdate;
     540             : }
     541             : 
     542           0 : void ScColorScaleFormat::DataChanged(const ScRange& rRange)
     543             : {
     544           0 :     bool bNeedUpdate = CheckEntriesForRel(rRange);
     545           0 :     if(bNeedUpdate)
     546             :     {
     547           0 :         mpDoc->RepaintRange(GetRange());
     548             :     }
     549           0 : }
     550             : 
     551           0 : condformat::ScFormatEntryType ScColorScaleFormat::GetType() const
     552             : {
     553           0 :     return condformat::COLORSCALE;
     554             : }
     555             : 
     556           0 : ScColorScaleFormat::iterator ScColorScaleFormat::begin()
     557             : {
     558           0 :     return maColorScales.begin();
     559             : }
     560             : 
     561           0 : ScColorScaleFormat::const_iterator ScColorScaleFormat::begin() const
     562             : {
     563           0 :     return maColorScales.begin();
     564             : }
     565             : 
     566           0 : ScColorScaleFormat::iterator ScColorScaleFormat::end()
     567             : {
     568           0 :     return maColorScales.end();
     569             : }
     570             : 
     571           0 : ScColorScaleFormat::const_iterator ScColorScaleFormat::end() const
     572             : {
     573           0 :     return maColorScales.end();
     574             : }
     575             : 
     576           0 : size_t ScColorScaleFormat::size() const
     577             : {
     578           0 :     return maColorScales.size();
     579             : }
     580             : 
     581           0 : ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc):
     582           0 :     ScColorFormat(pDoc)
     583             : {
     584           0 : }
     585             : 
     586           0 : ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc, const ScDataBarFormat& rFormat):
     587             :     ScColorFormat(pDoc),
     588           0 :     mpFormatData(new ScDataBarFormatData(*rFormat.mpFormatData))
     589             : {
     590           0 : }
     591             : 
     592           0 : void ScDataBarFormat::SetDataBarData( ScDataBarFormatData* pData )
     593             : {
     594           0 :     mpFormatData.reset(pData);
     595           0 : }
     596             : 
     597           0 : const ScDataBarFormatData* ScDataBarFormat::GetDataBarData() const
     598             : {
     599           0 :     return mpFormatData.get();
     600             : }
     601             : 
     602           0 : ScColorFormat* ScDataBarFormat::Clone(ScDocument* pDoc) const
     603             : {
     604           0 :     return new ScDataBarFormat(pDoc, *this);
     605             : }
     606             : 
     607           0 : condformat::ScFormatEntryType ScDataBarFormat::GetType() const
     608             : {
     609           0 :     return condformat::DATABAR;
     610             : }
     611             : 
     612           0 : void ScDataBarFormat::UpdateReference( UpdateRefMode eRefMode,
     613             :             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
     614             : {
     615           0 :     mpFormatData->mpUpperLimit->UpdateReference( eRefMode, rRange, nDx, nDy, nDz );
     616           0 :     mpFormatData->mpLowerLimit->UpdateReference( eRefMode, rRange, nDx, nDy, nDz );
     617           0 : }
     618             : 
     619             : namespace {
     620             : 
     621           0 : bool NeedUpdate(ScColorScaleEntry* pEntry)
     622             : {
     623           0 :     switch(pEntry->GetType())
     624             :     {
     625             :         case COLORSCALE_MIN:
     626             :         case COLORSCALE_MAX:
     627             :         case COLORSCALE_FORMULA:
     628             :         case COLORSCALE_AUTO:
     629           0 :             return true;
     630             :         default:
     631           0 :             return false;
     632             :     }
     633             : }
     634             : 
     635             : }
     636             : 
     637           0 : void ScDataBarFormat::DataChanged(const ScRange& rRange)
     638             : {
     639           0 :     bool bNeedUpdate = false;
     640             : 
     641           0 :     bNeedUpdate = NeedUpdate(mpFormatData->mpUpperLimit.get());
     642           0 :     bNeedUpdate &= NeedUpdate(mpFormatData->mpLowerLimit.get());
     643             : 
     644           0 :     bNeedUpdate &= GetRange().Intersects(rRange);
     645             : 
     646           0 :     if(bNeedUpdate)
     647             :     {
     648           0 :         mpDoc->RepaintRange(GetRange());
     649             :     }
     650           0 : }
     651             : 
     652           0 : void ScDataBarFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
     653             : {
     654           0 :     SCTAB nThisTab = GetRange().front()->aStart.Tab();
     655           0 :     mpFormatData->mpUpperLimit->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
     656           0 :     mpFormatData->mpLowerLimit->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
     657           0 : }
     658             : 
     659           0 : double ScDataBarFormat::getMin(double nMin, double nMax) const
     660             : {
     661           0 :     switch(mpFormatData->mpLowerLimit->GetType())
     662             :     {
     663             :         case COLORSCALE_MIN:
     664           0 :             return nMin;
     665             : 
     666             :         case COLORSCALE_AUTO:
     667           0 :             return std::min<double>(0, nMin);
     668             : 
     669             :         case COLORSCALE_PERCENT:
     670           0 :             return nMin + (nMax-nMin)/100*mpFormatData->mpLowerLimit->GetValue();
     671             : 
     672             :         case COLORSCALE_PERCENTILE:
     673             :         {
     674           0 :             double fPercentile = mpFormatData->mpLowerLimit->GetValue()/100.0;
     675           0 :             std::vector<double>& rValues = getValues();
     676           0 :             return GetPercentile(rValues, fPercentile);
     677             :         }
     678             : 
     679             :         default:
     680           0 :         break;
     681             :     }
     682             : 
     683           0 :     return mpFormatData->mpLowerLimit->GetValue();
     684             : }
     685             : 
     686           0 : double ScDataBarFormat::getMax(double nMin, double nMax) const
     687             : {
     688           0 :     switch(mpFormatData->mpUpperLimit->GetType())
     689             :     {
     690             :         case COLORSCALE_MAX:
     691           0 :             return nMax;
     692             :         case COLORSCALE_AUTO:
     693           0 :             return std::max<double>(0, nMax);
     694             :         case COLORSCALE_PERCENT:
     695           0 :             return nMin + (nMax-nMin)/100*mpFormatData->mpUpperLimit->GetValue();
     696             :         case COLORSCALE_PERCENTILE:
     697             :         {
     698           0 :             double fPercentile = mpFormatData->mpUpperLimit->GetValue()/100.0;
     699           0 :             std::vector<double>& rValues = getValues();
     700           0 :             return GetPercentile(rValues, fPercentile);
     701             :         }
     702             : 
     703             :         default:
     704           0 :             break;
     705             :     }
     706             : 
     707           0 :     return mpFormatData->mpUpperLimit->GetValue();
     708             : }
     709             : 
     710           0 : ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const
     711             : {
     712           0 :     CellType eCellType = mpDoc->GetCellType(rAddr);
     713           0 :     if(eCellType != CELLTYPE_VALUE && eCellType != CELLTYPE_FORMULA)
     714           0 :         return NULL;
     715             : 
     716           0 :     if (eCellType == CELLTYPE_FORMULA)
     717             :     {
     718           0 :         if(!static_cast<ScFormulaCell*>(mpDoc->GetCell(rAddr))->IsValue())
     719           0 :             return NULL;
     720             :     }
     721             : 
     722             :     // now we have for sure a value
     723             :     //
     724           0 :     double nValMin = getMinValue();
     725           0 :     double nValMax = getMaxValue();
     726           0 :     double nMin = getMin(nValMin, nValMax);
     727           0 :     double nMax = getMax(nValMin, nValMax);
     728             : 
     729             : 
     730           0 :     double nValue = mpDoc->GetValue(rAddr);
     731             : 
     732           0 :     ScDataBarInfo* pInfo = new ScDataBarInfo();
     733           0 :     if(mpFormatData->meAxisPosition == databar::NONE)
     734             :     {
     735           0 :         if(nValue <= nMin)
     736             :         {
     737           0 :             pInfo->mnLength = 0;
     738             :         }
     739           0 :         else if(nValue >= nMax)
     740             :         {
     741           0 :             pInfo->mnLength = 100;
     742             :         }
     743             :         else
     744             :         {
     745           0 :             double nDiff = nMax - nMin;
     746           0 :             pInfo->mnLength = (nValue - nMin)/nDiff*100.0;
     747             :         }
     748           0 :         pInfo->mnZero = 0;
     749             :     }
     750             :     else
     751             :     {
     752           0 :         double nMinPositive = 0;
     753           0 :         double nMaxNegative = 0;
     754             :         //calculate the zero position first
     755           0 :         if(mpFormatData->meAxisPosition == databar::AUTOMATIC)
     756             :         {
     757           0 :             if(nMin < 0)
     758             :             {
     759           0 :                 if(nMax < 0)
     760           0 :                     pInfo->mnZero = 100;
     761             :                 else
     762             :                 {
     763           0 :                     pInfo->mnZero = -100*nMin/(nMax-nMin);
     764             :                 }
     765             :             }
     766             :             else
     767           0 :                 pInfo->mnZero = 0;
     768             : 
     769             :             // if max or min is used we may need to adjust it
     770             :             // for the length calculation
     771           0 :             if (mpFormatData->mpLowerLimit->GetType() == COLORSCALE_MIN && nMin > 0)
     772           0 :                 nMinPositive = nMin;
     773           0 :             if (mpFormatData->mpUpperLimit->GetType() == COLORSCALE_MAX && nMax < 0)
     774           0 :                 nMaxNegative = nMax;
     775             :         }
     776           0 :         else if( mpFormatData->meAxisPosition == databar::MIDDLE)
     777           0 :             pInfo->mnZero = 50;
     778             : 
     779             :         //calculate the length
     780           0 :         if(nValue < 0)
     781             :         {
     782           0 :             if (nValue < nMin)
     783           0 :                 pInfo->mnLength = -100;
     784             :             else
     785           0 :                 pInfo->mnLength = -100 * (nValue-nMaxNegative)/(nMin-nMaxNegative);
     786             :         }
     787             :         else
     788             :         {
     789           0 :             if ( nValue > nMax )
     790           0 :                 pInfo->mnLength = 100;
     791             :             else
     792           0 :                 pInfo->mnLength = (nValue-nMinPositive)/(nMax-nMinPositive)*100;
     793             :         }
     794             :     }
     795             : 
     796             : 
     797             :     // set color
     798           0 :     if(mpFormatData->mbNeg && nValue < 0)
     799             :     {
     800           0 :         if(mpFormatData->mpNegativeColor)
     801             :         {
     802           0 :             pInfo->maColor = *mpFormatData->mpNegativeColor.get();
     803             :         }
     804             :         else
     805             :         {
     806             :             // default negative color is red
     807           0 :             pInfo->maColor = COL_LIGHTRED;
     808             :         }
     809             : 
     810             :     }
     811             :     else
     812           0 :         pInfo->maColor = mpFormatData->maPositiveColor;
     813             : 
     814           0 :     pInfo->mbGradient = mpFormatData->mbGradient;
     815           0 :     pInfo->mbShowValue = !mpFormatData->mbOnlyBar;
     816           0 :     pInfo->maAxisColor = mpFormatData->maAxisColor;
     817             : 
     818           0 :     return pInfo;
     819             : }
     820             : 
     821             : #if DUMP_FORMAT_INFO
     822           0 : void ScDataBarFormat::dumpInfo(rtl::OUStringBuffer& rBuf) const
     823             : {
     824           0 :     const ScRangeList& rRange = GetRange();
     825           0 :     size_t n = rRange.size();
     826           0 :     for(size_t i = 0; i < n; ++i)
     827             :     {
     828           0 :         const ScRange* pRange = rRange[i];
     829           0 :         SCTAB nTab = pRange->aStart.Tab();
     830           0 :         for( SCCOL nCol = pRange->aStart.Col(), nEndCol = pRange->aEnd.Col(); nCol <= nEndCol; ++nCol)
     831             :         {
     832           0 :             for( SCROW nRow = pRange->aStart.Row(), nEndRow = pRange->aEnd.Row(); nRow <= nEndRow; ++nRow)
     833             :             {
     834           0 :                 boost::scoped_ptr<ScDataBarInfo> pInfo( GetDataBarInfo(ScAddress(nCol, nRow, nTab)) );
     835           0 :                 rBuf.append((sal_Int32) nCol).append(",").append(nRow).append(",").append((sal_Int32) nTab).append(",").append(pInfo->mnZero).append(",");
     836           0 :                 rBuf.append(pInfo->mnLength).append(",").append((sal_Bool)pInfo->mbGradient).append(",").append((sal_Bool)pInfo->mbShowValue).append("\n");
     837           0 :             }
     838             :         }
     839             :     }
     840           0 : }
     841             : #endif
     842             : 
     843           0 : ScIconSetFormat::ScIconSetFormat(ScDocument* pDoc):
     844             :     ScColorFormat(pDoc),
     845           0 :     mpFormatData(new ScIconSetFormatData)
     846             : {
     847           0 : }
     848             : 
     849           0 : ScIconSetFormat::ScIconSetFormat(ScDocument* pDoc, const ScIconSetFormat& rFormat):
     850             :     ScColorFormat(pDoc),
     851           0 :     mpFormatData(new ScIconSetFormatData(*rFormat.mpFormatData))
     852             : {
     853           0 : }
     854             : 
     855           0 : ScColorFormat* ScIconSetFormat::Clone( ScDocument* pDoc ) const
     856             : {
     857           0 :     return new ScIconSetFormat(pDoc, *this);
     858             : }
     859             : 
     860           0 : void ScIconSetFormat::SetIconSetData( ScIconSetFormatData* pFormatData )
     861             : {
     862           0 :     mpFormatData.reset( pFormatData );
     863           0 : }
     864             : 
     865           0 : const ScIconSetFormatData* ScIconSetFormat::GetIconSetData() const
     866             : {
     867           0 :     return mpFormatData.get();
     868             : }
     869             : 
     870           0 : ScIconSetInfo* ScIconSetFormat::GetIconSetInfo(const ScAddress& rAddr) const
     871             : {
     872           0 :     CellType eCellType = mpDoc->GetCellType(rAddr);
     873           0 :     if(eCellType != CELLTYPE_VALUE && eCellType != CELLTYPE_FORMULA)
     874           0 :         return NULL;
     875             : 
     876           0 :     if (eCellType == CELLTYPE_FORMULA)
     877             :     {
     878           0 :         if(!static_cast<ScFormulaCell*>(mpDoc->GetCell(rAddr))->IsValue())
     879           0 :             return NULL;
     880             :     }
     881             : 
     882           0 :     ScIconSetInfo* pInfo = new ScIconSetInfo;
     883             : 
     884             :     // now we have for sure a value
     885           0 :     double nVal = mpDoc->GetValue(rAddr);
     886             : 
     887           0 :     if (mpFormatData->maEntries.size() < 2)
     888           0 :         return NULL;
     889             : 
     890           0 :     double nMin = GetMinValue();
     891           0 :     double nMax = GetMaxValue();
     892             : 
     893             :     // this check is for safety
     894           0 :     if(nMin >= nMax)
     895           0 :         return NULL;
     896             : 
     897           0 :     sal_Int32 nIndex = 0;
     898           0 :     const_iterator itr = begin();
     899           0 :     ++itr;
     900           0 :     double nValMax = CalcValue(nMin, nMax, itr);
     901             : 
     902           0 :     ++itr;
     903           0 :     while(itr != end() && nVal > nValMax)
     904             :     {
     905           0 :         ++nIndex;
     906           0 :         nValMax = CalcValue(nMin, nMax, itr);
     907           0 :         ++itr;
     908             :     }
     909           0 :     if(nVal > nValMax)
     910           0 :         ++nIndex;
     911             : 
     912           0 :     pInfo->nIconIndex = nIndex;
     913           0 :     pInfo->eIconSetType = mpFormatData->eIconSetType;
     914           0 :     return pInfo;
     915             : }
     916             : 
     917           0 : condformat::ScFormatEntryType ScIconSetFormat::GetType() const
     918             : {
     919           0 :     return condformat::ICONSET;
     920             : }
     921             : 
     922           0 : void ScIconSetFormat::DataChanged( const ScRange& )
     923             : {
     924           0 : }
     925             : 
     926           0 : void ScIconSetFormat::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab )
     927             : {
     928           0 :     for(iterator itr = begin(); itr != end(); ++itr)
     929             :     {
     930           0 :         itr->UpdateMoveTab(nOldTab, nNewTab, 0);
     931             :     }
     932           0 : }
     933             : 
     934           0 : void ScIconSetFormat::UpdateReference( UpdateRefMode eUpdateRefMode,
     935             :         const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
     936             : {
     937           0 :     for(iterator itr = begin(); itr != end(); ++itr)
     938             :     {
     939           0 :         itr->UpdateReference( eUpdateRefMode, rRange, nDx, nDy, nDz );
     940             :     }
     941           0 : }
     942             : 
     943           0 : void ScIconSetFormat::dumpInfo( rtl::OUStringBuffer& rBuffer ) const
     944             : {
     945           0 :     rBuffer.append("IconSet: \n");
     946           0 :     for(const_iterator itr = begin(); itr != end(); ++itr)
     947             :     {
     948           0 :         itr->dumpInfo(rBuffer);
     949             :     }
     950           0 : }
     951             : 
     952           0 : ScIconSetFormat::iterator ScIconSetFormat::begin()
     953             : {
     954           0 :     return mpFormatData->maEntries.begin();
     955             : }
     956             : 
     957           0 : ScIconSetFormat::const_iterator ScIconSetFormat::begin() const
     958             : {
     959           0 :     return mpFormatData->maEntries.begin();
     960             : }
     961             : 
     962           0 : ScIconSetFormat::iterator ScIconSetFormat::end()
     963             : {
     964           0 :     return mpFormatData->maEntries.end();
     965             : }
     966             : 
     967           0 : ScIconSetFormat::const_iterator ScIconSetFormat::end() const
     968             : {
     969           0 :     return mpFormatData->maEntries.end();
     970             : }
     971             : 
     972           0 : double ScIconSetFormat::GetMinValue() const
     973             : {
     974           0 :     const_iterator itr = begin();
     975             : 
     976           0 :     if(itr->GetType() == COLORSCALE_VALUE || itr->GetType() == COLORSCALE_FORMULA)
     977           0 :         return itr->GetValue();
     978             :     else
     979             :     {
     980           0 :         return getMinValue();
     981             :     }
     982             : }
     983             : 
     984           0 : double ScIconSetFormat::GetMaxValue() const
     985             : {
     986           0 :     boost::ptr_vector<ScColorScaleEntry>::const_reverse_iterator itr = mpFormatData->maEntries.rbegin();
     987             : 
     988           0 :     if(itr->GetType() == COLORSCALE_VALUE || itr->GetType() == COLORSCALE_FORMULA)
     989           0 :         return itr->GetValue();
     990             :     else
     991             :     {
     992           0 :         return getMaxValue();
     993             :     }
     994             : }
     995             : 
     996           0 : double ScIconSetFormat::CalcValue(double nMin, double nMax, ScIconSetFormat::const_iterator& itr) const
     997             : {
     998           0 :     switch(itr->GetType())
     999             :     {
    1000             :         case COLORSCALE_PERCENT:
    1001           0 :             return nMin + (nMax-nMin)*(itr->GetValue()/100);
    1002             :         case COLORSCALE_MIN:
    1003           0 :             return nMin;
    1004             :         case COLORSCALE_MAX:
    1005           0 :             return nMax;
    1006             :         case COLORSCALE_PERCENTILE:
    1007             :         {
    1008           0 :             std::vector<double>& rValues = getValues();
    1009           0 :             if(rValues.size() == 1)
    1010           0 :                 return rValues[0];
    1011             :             else
    1012             :             {
    1013           0 :                 double fPercentile = itr->GetValue()/100.0;
    1014           0 :                 return GetPercentile(rValues, fPercentile);
    1015             :             }
    1016             :         }
    1017             : 
    1018             :         default:
    1019           0 :         break;
    1020             :     }
    1021             : 
    1022           0 :     return itr->GetValue();
    1023             : }
    1024             : 
    1025           0 : ScIconSetMap* ScIconSetFormat::getIconSetMap()
    1026             : {
    1027             : 
    1028             :     static ScIconSetMap aIconSetMap[] = {
    1029             :         { "3Arrows", IconSet_3Arrows, 3 },
    1030             :         { "3ArrowsGray", IconSet_3ArrowsGray, 3 },
    1031             :         { "3Flags", IconSet_3Flags, 3 },
    1032             :         { "3TrafficLights1", IconSet_3TrafficLights1, 3 },
    1033             :         { "3TrafficLights2", IconSet_3TrafficLights2, 3 },
    1034             :         { "3Signs", IconSet_3Signs, 3 },
    1035             :         { "3Symbols", IconSet_3Symbols, 3 },
    1036             :         { "3Symbols2", IconSet_3Symbols2, 3 },
    1037             :         { "4Arrows", IconSet_4Arrows, 4 },
    1038             :         { "4ArrowsGray", IconSet_4ArrowsGray, 4 },
    1039             :         { "4RedToBlack", IconSet_4RedToBlack, 4 },
    1040             :         { "4Rating", IconSet_4Rating, 4 },
    1041             :         { "4TrafficLights", IconSet_4TrafficLights, 4 },
    1042             :         { "5Arrows", IconSet_5Arrows, 5 },
    1043             :         { "5ArrowsGray", IconSet_5ArrowsGray, 5 },
    1044             :         { "5Rating", IconSet_5Ratings, 5 },
    1045             :         { "5Quarters", IconSet_5Quarters, 5 },
    1046             :         { NULL, IconSet_3Arrows, 0 }
    1047             :     };
    1048             : 
    1049           0 :     return aIconSetMap;
    1050             : }
    1051             : 
    1052             : namespace {
    1053             : 
    1054             : sal_Int32 a3TrafficLights1[] = {
    1055             :     BMP_ICON_SET_CIRCLES1_RED, BMP_ICON_SET_CIRCLES1_YELLOW, BMP_ICON_SET_CIRCLES1_GREEN
    1056             : };
    1057             : 
    1058             : sal_Int32 a3TrafficLights2[] = {
    1059             :     BMP_ICON_SET_TRAFFICLIGHTS_RED, BMP_ICON_SET_TRAFFICLIGHTS_YELLOW, BMP_ICON_SET_TRAFFICLIGHTS_GREEN
    1060             : };
    1061             : 
    1062             : sal_Int32 a3Arrows[] = {
    1063             :     BMP_ICON_SET_COLORARROWS_DOWN, BMP_ICON_SET_COLORARROWS_SAME, BMP_ICON_SET_COLORARROWS_UP
    1064             : };
    1065             : 
    1066             : sal_Int32 a3ArrowsGray[] = {
    1067             :     BMP_ICON_SET_GRAYARROWS_DOWN, BMP_ICON_SET_GRAYARROWS_SAME, BMP_ICON_SET_GRAYARROWS_UP
    1068             : };
    1069             : 
    1070             : sal_Int32 a3Flags[] = {
    1071             :     BMP_ICON_SET_FLAGS_RED, BMP_ICON_SET_FLAGS_YELLOW, BMP_ICON_SET_FLAGS_GREEN
    1072             : };
    1073             : 
    1074             : sal_Int32 a4Arrows[] = {
    1075             :     BMP_ICON_SET_COLORARROWS_DOWN, BMP_ICON_SET_COLORARROWS_SLIGHTLY_DOWN, BMP_ICON_SET_COLORARROWS_SLIGHTLY_UP, BMP_ICON_SET_COLORARROWS_UP
    1076             : };
    1077             : 
    1078             : sal_Int32 a4ArrowsGray[] = {
    1079             :     BMP_ICON_SET_GRAYARROWS_DOWN, BMP_ICON_SET_GRAYARROWS_SLIGHTLY_DOWN, BMP_ICON_SET_GRAYARROWS_SLIGHTLY_UP, BMP_ICON_SET_GRAYARROWS_UP
    1080             : };
    1081             : 
    1082             : sal_Int32 a5Arrows[] = {
    1083             :     BMP_ICON_SET_COLORARROWS_DOWN, BMP_ICON_SET_COLORARROWS_SLIGHTLY_DOWN,
    1084             :     BMP_ICON_SET_COLORARROWS_SAME, BMP_ICON_SET_COLORARROWS_SLIGHTLY_UP, BMP_ICON_SET_COLORARROWS_UP
    1085             : };
    1086             : 
    1087             : sal_Int32 a5ArrowsGray[] = {
    1088             :     BMP_ICON_SET_GRAYARROWS_DOWN, BMP_ICON_SET_GRAYARROWS_SLIGHTLY_DOWN,
    1089             :     BMP_ICON_SET_GRAYARROWS_SAME, BMP_ICON_SET_GRAYARROWS_SLIGHTLY_UP, BMP_ICON_SET_GRAYARROWS_UP
    1090             : };
    1091             : 
    1092             : sal_Int32 a4TrafficLights[] = {
    1093             :     BMP_ICON_SET_CIRCLES1_GRAY, BMP_ICON_SET_CIRCLES1_RED,
    1094             :     BMP_ICON_SET_CIRCLES1_YELLOW, BMP_ICON_SET_CIRCLES1_GREEN
    1095             : };
    1096             : 
    1097             : sal_Int32 a5Quarters[] = {
    1098             :     BMP_ICON_SET_PIES_EMPTY, BMP_ICON_SET_PIES_ONE_QUARTER, BMP_ICON_SET_PIES_HALF,
    1099             :     BMP_ICON_SET_PIES_THREE_QUARTER, BMP_ICON_SET_PIES_FULL,
    1100             : };
    1101             : 
    1102             : sal_Int32 a3Symbols1[] = {
    1103             :     BMP_ICON_SET_SYMBOLS1_CHECK, BMP_ICON_SET_SYMBOLS1_EXCLAMATION_MARK, BMP_ICON_SET_SYMBOLS1_CROSS
    1104             : };
    1105             : 
    1106             : sal_Int32 a3Signs[] = {
    1107             :     BMP_ICON_SET_SHAPES_DIAMOND, BMP_ICON_SET_SHAPES_TRIANGLE, BMP_ICON_SET_SHAPES_CIRCLE
    1108             : };
    1109             : 
    1110             : sal_Int32 a4RedToBlack[] = {
    1111             :     BMP_ICON_SET_CIRCLES2_DARK_GRAY, BMP_ICON_SET_CIRCLES2_LIGHT_GRAY,
    1112             :     BMP_ICON_SET_CIRCLES2_LIGHT_RED, BMP_ICON_SET_CIRCLES2_DARK_RED
    1113             : };
    1114             : 
    1115             : sal_Int32 a4Ratings[] = {
    1116             :     BMP_ICON_SET_BARS_ONE_QUARTER, BMP_ICON_SET_BARS_HALF,
    1117             :     BMP_ICON_SET_BARS_THREE_QUARTER, BMP_ICON_SET_BARS_FULL
    1118             : };
    1119             : 
    1120             : sal_Int32 a5Ratings[] = {
    1121             :     BMP_ICON_SET_BARS_EMPTY, BMP_ICON_SET_BARS_ONE_QUARTER, BMP_ICON_SET_BARS_HALF,
    1122             :     BMP_ICON_SET_BARS_THREE_QUARTER, BMP_ICON_SET_BARS_FULL
    1123             : };
    1124             : 
    1125             : struct ScIconSetBitmapMap {
    1126             :     ScIconSetType eType;
    1127             :     sal_Int32* nBitmaps;
    1128             : };
    1129             : 
    1130             : static ScIconSetBitmapMap aBitmapMap[] = {
    1131             :     { IconSet_3Arrows, a3Arrows },
    1132             :     { IconSet_3ArrowsGray, a3ArrowsGray },
    1133             :     { IconSet_3Flags, a3Flags },
    1134             :     { IconSet_3Signs, a3Signs },
    1135             :     { IconSet_3Symbols, a3Symbols1 },
    1136             :     { IconSet_3Symbols2, a3Symbols1 },
    1137             :     { IconSet_3TrafficLights1, a3TrafficLights1 },
    1138             :     { IconSet_3TrafficLights2, a3TrafficLights2 },
    1139             :     { IconSet_4Arrows, a4Arrows },
    1140             :     { IconSet_4ArrowsGray, a4ArrowsGray },
    1141             :     { IconSet_4Rating, a4Ratings },
    1142             :     { IconSet_4RedToBlack, a4RedToBlack },
    1143             :     { IconSet_4TrafficLights, a4TrafficLights },
    1144             :     { IconSet_5Arrows, a5Arrows },
    1145             :     { IconSet_5ArrowsGray, a5ArrowsGray },
    1146             :     { IconSet_5Quarters, a5Quarters },
    1147             :     { IconSet_5Ratings, a5Ratings }
    1148             : };
    1149             : 
    1150             : }
    1151             : 
    1152           0 : BitmapEx& ScIconSetFormat::getBitmap( ScIconSetType eType, sal_Int32 nIndex )
    1153             : {
    1154           0 :     static std::map< sal_Int32, BitmapEx > aIconSetBitmaps;
    1155             : 
    1156           0 :     sal_Int32 nBitmap = -1;
    1157             : 
    1158           0 :     for(size_t i = 0; i < SAL_N_ELEMENTS(aBitmapMap); ++i)
    1159             :     {
    1160           0 :         if(aBitmapMap[i].eType == eType)
    1161             :         {
    1162           0 :             nBitmap = *(aBitmapMap[i].nBitmaps + nIndex);
    1163             :         }
    1164             :     }
    1165             :     assert( nBitmap != -1 );
    1166             : 
    1167           0 :     std::map<sal_Int32, BitmapEx>::iterator itr = aIconSetBitmaps.find( nBitmap );
    1168           0 :     if(itr != aIconSetBitmaps.end())
    1169           0 :         return itr->second;
    1170             : 
    1171           0 :     BitmapEx aBitmap = BitmapEx(ScResId(nBitmap));
    1172           0 :     std::pair<sal_Int32, BitmapEx> aPair( nBitmap, aBitmap );
    1173           0 :     std::pair<std::map<sal_Int32, BitmapEx>::iterator, bool> itrNew = aIconSetBitmaps.insert(aPair);
    1174             :     assert(itrNew.second);
    1175             : 
    1176           0 :     return itrNew.first->second;
    1177         102 : }
    1178             : 
    1179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10