LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlcondformat.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 302 461 65.5 %
Date: 2014-04-11 Functions: 15 19 78.9 %
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             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #include "xmlcondformat.hxx"
      11             : #include <xmloff/nmspmap.hxx>
      12             : 
      13             : #include "colorscale.hxx"
      14             : #include "conditio.hxx"
      15             : #include "document.hxx"
      16             : #include <sax/tools/converter.hxx>
      17             : #include "rangelst.hxx"
      18             : #include "rangeutl.hxx"
      19             : #include "docfunc.hxx"
      20             : #include "XMLConverter.hxx"
      21             : #include "stylehelper.hxx"
      22             : 
      23             : 
      24          13 : ScXMLConditionalFormatsContext::ScXMLConditionalFormatsContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
      25             :                         const OUString& rLName):
      26          13 :     SvXMLImportContext( rImport, nPrfx, rLName )
      27             : {
      28          13 :     GetScImport().SetNewCondFormatData();
      29          13 :     GetScImport().GetDocument()->SetCondFormList(new ScConditionalFormatList(), GetScImport().GetTables().GetCurrentSheet());
      30          13 : }
      31             : 
      32          56 : SvXMLImportContext* ScXMLConditionalFormatsContext::CreateChildContext( sal_uInt16 nPrefix,
      33             :         const OUString& rLocalName,
      34             :         const ::com::sun::star::uno::Reference<
      35             :         ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
      36             : {
      37          56 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCondFormatsTokenMap();
      38          56 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
      39          56 :     SvXMLImportContext* pContext = NULL;
      40          56 :     switch (nToken)
      41             :     {
      42             :         case XML_TOK_CONDFORMATS_CONDFORMAT:
      43          56 :             pContext = new ScXMLConditionalFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList );
      44          56 :             break;
      45             :     }
      46             : 
      47          56 :     return pContext;
      48             : }
      49             : 
      50          13 : void ScXMLConditionalFormatsContext::EndElement()
      51             : {
      52          13 :     ScDocument* pDoc = GetScImport().GetDocument();
      53             : 
      54          13 :     SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
      55          13 :     ScConditionalFormatList* pCondFormatList = pDoc->GetCondFormList(nTab);
      56          13 :     bool bDeleted = !pCondFormatList->CheckAllEntries();
      57             : 
      58             :     SAL_WARN_IF(bDeleted, "sc", "conditional formats have been deleted because they contained empty range info");
      59          13 : }
      60             : 
      61          56 : ScXMLConditionalFormatContext::ScXMLConditionalFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
      62             :                         const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList):
      63          56 :     SvXMLImportContext( rImport, nPrfx, rLName )
      64             : {
      65          56 :     OUString sRange;
      66             : 
      67          56 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      68          56 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetCondFormatAttrMap();
      69         112 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      70             :     {
      71          56 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
      72         112 :         OUString aLocalName;
      73          56 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
      74          56 :                     sAttrName, &aLocalName ));
      75         112 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
      76             : 
      77          56 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      78             :         {
      79             :             case XML_TOK_CONDFORMAT_TARGET_RANGE:
      80          56 :                 sRange = sValue;
      81          56 :             break;
      82             :             default:
      83           0 :                 break;
      84             :         }
      85          56 :     }
      86             : 
      87          56 :     ScRangeStringConverter::GetRangeListFromString(maRange, sRange, GetScImport().GetDocument(),
      88          56 :             formula::FormulaGrammar::CONV_ODF);
      89             : 
      90          56 :     mpFormat = new ScConditionalFormat(0, GetScImport().GetDocument());
      91          56 :     mpFormat->AddRange(maRange);
      92          56 : }
      93             : 
      94          80 : SvXMLImportContext* ScXMLConditionalFormatContext::CreateChildContext( sal_uInt16 nPrefix,
      95             :         const OUString& rLocalName,
      96             :         const ::com::sun::star::uno::Reference<
      97             :         ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
      98             : {
      99          80 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCondFormatTokenMap();
     100          80 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
     101          80 :     SvXMLImportContext* pContext = NULL;
     102          80 :     switch (nToken)
     103             :     {
     104             :         case XML_TOK_CONDFORMAT_CONDITION:
     105          57 :             pContext = new ScXMLCondContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
     106          57 :             break;
     107             :         case XML_TOK_CONDFORMAT_COLORSCALE:
     108          18 :             pContext = new ScXMLColorScaleFormatContext( GetScImport(), nPrefix, rLocalName, mpFormat );
     109          18 :             break;
     110             :         case XML_TOK_CONDFORMAT_DATABAR:
     111           5 :             pContext = new ScXMLDataBarFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
     112           5 :             break;
     113             :         case XML_TOK_CONDFORMAT_ICONSET:
     114           0 :             pContext = new ScXMLIconSetFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
     115           0 :             break;
     116             :         case XML_TOK_CONDFORMAT_DATE:
     117           0 :             pContext = new ScXMLDateContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
     118           0 :             break;
     119             :         default:
     120           0 :             break;
     121             :     }
     122             : 
     123          80 :     return pContext;
     124             : }
     125             : 
     126          56 : void ScXMLConditionalFormatContext::EndElement()
     127             : {
     128          56 :     ScDocument* pDoc = GetScImport().GetDocument();
     129             : 
     130          56 :     SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
     131          56 :     sal_uLong nIndex = pDoc->AddCondFormat(mpFormat, nTab);
     132          56 :     mpFormat->SetKey(nIndex);
     133             : 
     134          56 :     pDoc->AddCondFormatData( mpFormat->GetRange(), nTab, nIndex);
     135          56 : }
     136             : 
     137          18 : ScXMLColorScaleFormatContext::ScXMLColorScaleFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
     138             :                         const OUString& rLName, ScConditionalFormat* pFormat):
     139             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     140          18 :     pColorScaleFormat(NULL)
     141             : {
     142          18 :     pColorScaleFormat = new ScColorScaleFormat(GetScImport().GetDocument());
     143          18 :     pFormat->AddEntry(pColorScaleFormat);
     144          18 : }
     145             : 
     146          45 : SvXMLImportContext* ScXMLColorScaleFormatContext::CreateChildContext( sal_uInt16 nPrefix,
     147             :         const OUString& rLocalName,
     148             :         const ::com::sun::star::uno::Reference<
     149             :         ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     150             : {
     151          45 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetColorScaleTokenMap();
     152          45 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
     153          45 :     SvXMLImportContext* pContext = NULL;
     154          45 :     switch (nToken)
     155             :     {
     156             :         case XML_TOK_COLORSCALE_COLORSCALEENTRY:
     157          45 :             pContext = new ScXMLColorScaleFormatEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pColorScaleFormat );
     158          45 :             break;
     159             :         default:
     160           0 :             break;
     161             :     }
     162             : 
     163          45 :     return pContext;
     164             : }
     165             : 
     166           5 : ScXMLDataBarFormatContext::ScXMLDataBarFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
     167             :                         const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     168             :                         ScConditionalFormat* pFormat):
     169             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     170             :     mpDataBarFormat(NULL),
     171           5 :     mpFormatData(NULL)
     172             : {
     173           5 :     OUString sPositiveColor;
     174          10 :     OUString sNegativeColor;
     175          10 :     OUString sGradient;
     176          10 :     OUString sAxisPosition;
     177          10 :     OUString sShowValue;
     178          10 :     OUString sAxisColor;
     179             : 
     180           5 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     181           5 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataBarAttrMap();
     182          21 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     183             :     {
     184          16 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     185          32 :         OUString aLocalName;
     186          16 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     187          16 :                     sAttrName, &aLocalName ));
     188          32 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     189             : 
     190          16 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     191             :         {
     192             :             case XML_TOK_DATABAR_POSITIVE_COLOR:
     193           5 :                 sPositiveColor = sValue;
     194           5 :                 break;
     195             :             case XML_TOK_DATABAR_GRADIENT:
     196           0 :                 sGradient = sValue;
     197           0 :                 break;
     198             :             case XML_TOK_DATABAR_NEGATIVE_COLOR:
     199           5 :                 sNegativeColor = sValue;
     200           5 :                 break;
     201             :             case XML_TOK_DATABAR_AXISPOSITION:
     202           1 :                 sAxisPosition = sValue;
     203           1 :                 break;
     204             :             case XML_TOK_DATABAR_SHOWVALUE:
     205           0 :                 sShowValue = sValue;
     206           0 :                 break;
     207             :             case XML_TOK_DATABAR_AXISCOLOR:
     208           5 :                 sAxisColor = sValue;
     209           5 :                 break;
     210             :             default:
     211           0 :                 break;
     212             :         }
     213          16 :     }
     214             : 
     215           5 :     mpDataBarFormat = new ScDataBarFormat(rImport.GetDocument());
     216           5 :     mpFormatData = new ScDataBarFormatData();
     217           5 :     mpDataBarFormat->SetDataBarData(mpFormatData);
     218           5 :     if(!sGradient.isEmpty())
     219             :     {
     220           0 :         bool bGradient = true;
     221           0 :         sax::Converter::convertBool( bGradient, sGradient);
     222           0 :         mpFormatData->mbGradient = bGradient;
     223             :     }
     224             : 
     225           5 :     if(!sPositiveColor.isEmpty())
     226             :     {
     227           5 :         sal_Int32 nColor = 0;
     228           5 :         sax::Converter::convertColor( nColor, sPositiveColor );
     229           5 :         mpFormatData->maPositiveColor = Color(nColor);
     230             :     }
     231             : 
     232           5 :     if(!sNegativeColor.isEmpty())
     233             :     {
     234             :         // we might check here for 0xff0000 and don't write it
     235           5 :         sal_Int32 nColor = 0;
     236           5 :         sax::Converter::convertColor( nColor, sNegativeColor );
     237           5 :         mpFormatData->mpNegativeColor.reset(new Color(nColor));
     238             :     }
     239             :     else
     240           0 :         mpFormatData->mbNeg = false;
     241             : 
     242           5 :     if(!sAxisPosition.isEmpty())
     243             :     {
     244           1 :         if(sAxisPosition == "middle")
     245           1 :             mpFormatData->meAxisPosition = databar::MIDDLE;
     246           0 :         else if (sAxisPosition == "none")
     247           0 :             mpFormatData->meAxisPosition = databar::NONE;
     248             :     }
     249             : 
     250           5 :     if(!sAxisColor.isEmpty())
     251             :     {
     252           5 :         sal_Int32 nColor = 0;
     253           5 :         sax::Converter::convertColor( nColor, sAxisColor );
     254           5 :         mpFormatData->maAxisColor = Color(nColor);
     255             :     }
     256             : 
     257           5 :     if(!sShowValue.isEmpty())
     258             :     {
     259           0 :         bool bShowValue = true;
     260           0 :         sax::Converter::convertBool( bShowValue, sShowValue );
     261           0 :         mpFormatData->mbOnlyBar = !bShowValue;
     262             :     }
     263             : 
     264          10 :     pFormat->AddEntry(mpDataBarFormat);
     265           5 : }
     266             : 
     267          10 : SvXMLImportContext* ScXMLDataBarFormatContext::CreateChildContext( sal_uInt16 nPrefix,
     268             :         const OUString& rLocalName,
     269             :         const ::com::sun::star::uno::Reference<
     270             :         ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     271             : {
     272          10 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetFormattingTokenMap();
     273          10 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
     274          10 :     SvXMLImportContext* pContext = NULL;
     275          10 :     switch (nToken)
     276             :     {
     277             :         case XML_TOK_FORMATTING_ENTRY:
     278             :         case XML_TOK_DATABAR_DATABARENTRY:
     279             :         {
     280          10 :             ScColorScaleEntry* pEntry(0);
     281          10 :             pContext = new ScXMLFormattingEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry );
     282          10 :             if(mpFormatData->mpLowerLimit)
     283             :             {
     284           5 :                 mpFormatData->mpUpperLimit.reset(pEntry);
     285             :             }
     286             :             else
     287             :             {
     288           5 :                 mpFormatData->mpLowerLimit.reset(pEntry);
     289             :             }
     290             :         }
     291          10 :         break;
     292             :         default:
     293           0 :             break;
     294             :     }
     295             : 
     296          10 :     return pContext;
     297             : }
     298             : 
     299           0 : ScXMLIconSetFormatContext::ScXMLIconSetFormatContext(ScXMLImport& rImport, sal_uInt16 nPrfx,
     300             :                         const OUString& rLName,
     301             :                         const ::com::sun::star::uno::Reference<
     302             :                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     303             :                         ScConditionalFormat* pFormat):
     304           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
     305             : {
     306           0 :     OUString aIconSetType, sShowValue;
     307           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     308           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetIconSetAttrMap();
     309           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     310             :     {
     311           0 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     312           0 :         OUString aLocalName;
     313           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     314           0 :                     sAttrName, &aLocalName ));
     315           0 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     316             : 
     317           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     318             :         {
     319             :             case XML_TOK_ICONSET_TYPE:
     320           0 :                 aIconSetType = sValue;
     321           0 :                 break;
     322             :             case XML_TOK_ICONSET_SHOWVALUE:
     323           0 :                 sShowValue = sValue;
     324           0 :                 break;
     325             :             default:
     326           0 :                 break;
     327             :         }
     328           0 :     }
     329             : 
     330           0 :     ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
     331           0 :     ScIconSetType eType = IconSet_3Arrows;
     332           0 :     for(; pMap->pName; ++pMap)
     333             :     {
     334           0 :         OUString aName = OUString::createFromAscii(pMap->pName);
     335           0 :         if(aName ==aIconSetType)
     336             :         {
     337           0 :             eType = pMap->eType;
     338           0 :             break;
     339             :         }
     340           0 :     }
     341             : 
     342           0 :     ScIconSetFormat* pIconSetFormat = new ScIconSetFormat(GetScImport().GetDocument());
     343           0 :     ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData;
     344             : 
     345           0 :     if(!sShowValue.isEmpty())
     346             :     {
     347           0 :         bool bShowValue = true;
     348           0 :         sax::Converter::convertBool( bShowValue, sShowValue );
     349           0 :         pIconSetFormatData->mbShowValue = !bShowValue;
     350             :     }
     351             : 
     352           0 :     pIconSetFormatData->eIconSetType = eType;
     353           0 :     pIconSetFormat->SetIconSetData(pIconSetFormatData);
     354           0 :     pFormat->AddEntry(pIconSetFormat);
     355             : 
     356           0 :     mpFormatData = pIconSetFormatData;
     357           0 : }
     358             : 
     359           0 : SvXMLImportContext* ScXMLIconSetFormatContext::CreateChildContext( sal_uInt16 nPrefix,
     360             :         const OUString& rLocalName,
     361             :         const ::com::sun::star::uno::Reference<
     362             :         ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     363             : {
     364           0 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetFormattingTokenMap();
     365           0 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
     366           0 :     SvXMLImportContext* pContext = NULL;
     367           0 :     switch (nToken)
     368             :     {
     369             :         case XML_TOK_FORMATTING_ENTRY:
     370             :             {
     371           0 :                 ScColorScaleEntry* pEntry(0);
     372           0 :                 pContext = new ScXMLFormattingEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry );
     373           0 :                 mpFormatData->maEntries.push_back(pEntry);
     374             :             }
     375           0 :             break;
     376             :         default:
     377           0 :             break;
     378             :     }
     379             : 
     380           0 :     return pContext;
     381             : }
     382             : 
     383             : namespace {
     384             : 
     385          57 : void GetConditionData(const OUString& rValue, ScConditionMode& eMode, OUString& rExpr1, OUString& rExpr2)
     386             : {
     387          57 :     if(rValue.startsWith("unique"))
     388             :     {
     389           0 :         eMode = SC_COND_NOTDUPLICATE;
     390             :     }
     391          57 :     else if(rValue.startsWith("duplicate"))
     392             :     {
     393           0 :         eMode = SC_COND_DUPLICATE;
     394             :     }
     395          57 :     else if(rValue.startsWith("between"))
     396             :     {
     397           3 :         const sal_Unicode* pStr = rValue.getStr();
     398           3 :         const sal_Unicode* pStart = pStr + 8;
     399           3 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     400           3 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ',');
     401           3 :         rExpr2 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     402           3 :         eMode = SC_COND_BETWEEN;
     403             :     }
     404          54 :     else if(rValue.startsWith("not-between"))
     405             :     {
     406           6 :         const sal_Unicode* pStr = rValue.getStr();
     407           6 :         const sal_Unicode* pStart = pStr + 12;
     408           6 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     409           6 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ',');
     410           6 :         rExpr2 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     411           6 :         eMode = SC_COND_NOTBETWEEN;
     412             :     }
     413          48 :     else if(rValue.startsWith("<="))
     414             :     {
     415           0 :         rExpr1 = rValue.copy(2);
     416           0 :         eMode = SC_COND_EQLESS;
     417             :     }
     418          48 :     else if(rValue.startsWith(">="))
     419             :     {
     420           6 :         rExpr1 = rValue.copy(2);
     421           6 :         eMode = SC_COND_EQGREATER;
     422             :     }
     423          42 :     else if(rValue.startsWith("!="))
     424             :     {
     425           0 :         rExpr1 = rValue.copy(2);
     426           0 :         eMode = SC_COND_NOTEQUAL;
     427             :     }
     428          42 :     else if(rValue.startsWith("<"))
     429             :     {
     430           3 :         rExpr1 = rValue.copy(1);
     431           3 :         eMode = SC_COND_LESS;
     432             :     }
     433          39 :     else if(rValue.startsWith("="))
     434             :     {
     435           6 :         rExpr1 = rValue.copy(1);
     436           6 :         eMode = SC_COND_EQUAL;
     437             :     }
     438          33 :     else if(rValue.startsWith(">"))
     439             :     {
     440           3 :         rExpr1 = rValue.copy(1);
     441           3 :         eMode = SC_COND_GREATER;
     442             :     }
     443          30 :     else if(rValue.startsWith("formula-is"))
     444             :     {
     445           6 :         const sal_Unicode* pStr = rValue.getStr();
     446           6 :         const sal_Unicode* pStart = pStr + 11;
     447           6 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     448           6 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     449           6 :         eMode = SC_COND_DIRECT;
     450             :     }
     451          24 :     else if(rValue.startsWith("top-elements"))
     452             :     {
     453           3 :         const sal_Unicode* pStr = rValue.getStr();
     454           3 :         const sal_Unicode* pStart = pStr + 13;
     455           3 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     456           3 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     457           3 :         eMode = SC_COND_TOP10;
     458             :     }
     459          21 :     else if(rValue.startsWith("bottom-elements"))
     460             :     {
     461           3 :         const sal_Unicode* pStr = rValue.getStr();
     462           3 :         const sal_Unicode* pStart = pStr + 16;
     463           3 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     464           3 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     465           3 :         eMode = SC_COND_BOTTOM10;
     466             :     }
     467          18 :     else if(rValue.startsWith("top-percent"))
     468             :     {
     469           3 :         const sal_Unicode* pStr = rValue.getStr();
     470           3 :         const sal_Unicode* pStart = pStr + 12;
     471           3 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     472           3 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     473           3 :         eMode = SC_COND_TOP_PERCENT;
     474             :     }
     475          15 :     else if(rValue.startsWith("bottom-percent"))
     476             :     {
     477           3 :         const sal_Unicode* pStr = rValue.getStr();
     478           3 :         const sal_Unicode* pStart = pStr + 15;
     479           3 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     480           3 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     481           3 :         eMode = SC_COND_BOTTOM_PERCENT;
     482             :     }
     483          12 :     else if(rValue.startsWith("above-average"))
     484             :     {
     485           3 :         eMode = SC_COND_ABOVE_AVERAGE;
     486             :     }
     487           9 :     else if(rValue.startsWith("below-average"))
     488             :     {
     489           3 :         eMode = SC_COND_BELOW_AVERAGE;
     490             :     }
     491           6 :     else if(rValue.startsWith("above-equal-average"))
     492             :     {
     493           3 :         eMode = SC_COND_ABOVE_EQUAL_AVERAGE;
     494             :     }
     495           3 :     else if(rValue.startsWith("below-equal-average"))
     496             :     {
     497           3 :         eMode = SC_COND_BELOW_EQUAL_AVERAGE;
     498             :     }
     499           0 :     else if(rValue.startsWith("is-error"))
     500             :     {
     501           0 :         eMode = SC_COND_ERROR;
     502             :     }
     503           0 :     else if(rValue.startsWith("is-no-error"))
     504             :     {
     505           0 :         eMode = SC_COND_NOERROR;
     506             :     }
     507           0 :     else if(rValue.startsWith("begins-with"))
     508             :     {
     509           0 :         eMode = SC_COND_BEGINS_WITH;
     510           0 :         const sal_Unicode* pStr = rValue.getStr();
     511           0 :         const sal_Unicode* pStart = pStr + 12;
     512           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     513           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     514             :     }
     515           0 :     else if(rValue.startsWith("ends-with"))
     516             :     {
     517           0 :         eMode = SC_COND_ENDS_WITH;
     518           0 :         const sal_Unicode* pStr = rValue.getStr();
     519           0 :         const sal_Unicode* pStart = pStr + 10;
     520           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     521           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     522             :     }
     523           0 :     else if(rValue.startsWith("contains-text"))
     524             :     {
     525           0 :         eMode = SC_COND_CONTAINS_TEXT;
     526           0 :         const sal_Unicode* pStr = rValue.getStr();
     527           0 :         const sal_Unicode* pStart = pStr + 14;
     528           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     529           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     530             :     }
     531           0 :     else if(rValue.startsWith("not-contains-text"))
     532             :     {
     533           0 :         eMode = SC_COND_NOT_CONTAINS_TEXT;
     534           0 :         const sal_Unicode* pStr = rValue.getStr();
     535           0 :         const sal_Unicode* pStart = pStr + 18;
     536           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     537           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     538             :     }
     539             :     else
     540           0 :         eMode = SC_COND_NONE;
     541          57 : }
     542             : 
     543             : }
     544             : 
     545          57 : ScXMLCondContext::ScXMLCondContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
     546             :                         const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     547             :                         ScConditionalFormat* pFormat ):
     548          57 :     SvXMLImportContext( rImport, nPrfx, rLName )
     549             : {
     550          57 :     OUString sExpression;
     551         114 :     OUString sStyle;
     552         114 :     OUString sAddress;
     553             : 
     554          57 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     555          57 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetConditionAttrMap();
     556         228 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     557             :     {
     558         171 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     559         342 :         OUString aLocalName;
     560         171 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     561         171 :                     sAttrName, &aLocalName ));
     562         342 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     563             : 
     564         171 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     565             :         {
     566             :             case XML_TOK_CONDITION_VALUE:
     567          57 :                 sExpression = sValue;
     568          57 :                 break;
     569             :             case XML_TOK_CONDITION_APPLY_STYLE_NAME:
     570          57 :                 sStyle = ScStyleNameConversion::ProgrammaticToDisplayName(sValue, SFX_STYLE_FAMILY_PARA );
     571          57 :                 break;
     572             :             case XML_TOK_CONDITION_BASE_CELL_ADDRESS:
     573          57 :                 sAddress = sValue;
     574          57 :                 break;
     575             :             default:
     576           0 :                 break;
     577             :         }
     578         171 :     }
     579             : 
     580          57 :     OUString aExpr1;
     581         114 :     OUString aExpr2;
     582             :     ScConditionMode eMode;
     583          57 :     GetConditionData(sExpression, eMode, aExpr1, aExpr2);
     584             : 
     585          57 :     ScCondFormatEntry* pFormatEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, GetScImport().GetDocument(), ScAddress(), sStyle,
     586          57 :                                                         OUString(), OUString(), formula::FormulaGrammar::GRAM_ODFF, formula::FormulaGrammar::GRAM_ODFF);
     587          57 :     pFormatEntry->SetSrcString(sAddress);
     588             : 
     589         171 :     pFormat->AddEntry(pFormatEntry);
     590          57 : }
     591             : 
     592             : namespace {
     593             : 
     594          55 : void setColorEntryType(const OUString& rType, ScColorScaleEntry* pEntry, const OUString& rFormula,
     595             :         ScXMLImport& rImport)
     596             : {
     597          55 :     if(rType == "minimum")
     598           7 :         pEntry->SetType(COLORSCALE_MIN);
     599          48 :     else if(rType == "maximum")
     600           7 :         pEntry->SetType(COLORSCALE_MAX);
     601          41 :     else if(rType == "percentile")
     602          10 :         pEntry->SetType(COLORSCALE_PERCENTILE);
     603          31 :     else if(rType == "percent")
     604           7 :         pEntry->SetType(COLORSCALE_PERCENT);
     605          24 :     else if(rType == "formula")
     606             :     {
     607           7 :         pEntry->SetType(COLORSCALE_FORMULA);
     608             :         //position does not matter, only table is important
     609           7 :         pEntry->SetFormula(rFormula, rImport.GetDocument(), ScAddress(0,0,rImport.GetTables().GetCurrentSheet()), formula::FormulaGrammar::GRAM_ODFF);
     610             :     }
     611          17 :     else if(rType == "auto-minimum")
     612           2 :         pEntry->SetType(COLORSCALE_AUTO);
     613          15 :     else if(rType == "auto-maximum")
     614           2 :         pEntry->SetType(COLORSCALE_AUTO);
     615          55 : }
     616             : 
     617             : }
     618             : 
     619          45 : ScXMLColorScaleFormatEntryContext::ScXMLColorScaleFormatEntryContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
     620             :                         const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     621             :                         ScColorScaleFormat* pFormat):
     622             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     623          45 :     mpFormatEntry( NULL )
     624             : {
     625          45 :     double nVal = 0;
     626          45 :     Color aColor;
     627             : 
     628          45 :     OUString sType;
     629          90 :     OUString sVal;
     630          90 :     OUString sColor;
     631             : 
     632          45 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     633          45 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetColorScaleEntryAttrMap();
     634         180 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     635             :     {
     636         135 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     637         270 :         OUString aLocalName;
     638         135 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     639         135 :                     sAttrName, &aLocalName ));
     640         270 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     641             : 
     642         135 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     643             :         {
     644             :             case XML_TOK_COLORSCALEENTRY_TYPE:
     645          45 :                 sType = sValue;
     646          45 :                 break;
     647             :             case XML_TOK_COLORSCALEENTRY_VALUE:
     648          45 :                 sVal = sValue;
     649          45 :                 break;
     650             :             case XML_TOK_COLORSCALEENTRY_COLOR:
     651          45 :                 sColor = sValue;
     652          45 :                 break;
     653             :             default:
     654           0 :                 break;
     655             :         }
     656         135 :     }
     657             : 
     658             :     sal_Int32 nColor;
     659          45 :     sax::Converter::convertColor(nColor, sColor);
     660          45 :     aColor = Color(nColor);
     661             : 
     662          45 :     if(!sVal.isEmpty())
     663          45 :         sax::Converter::convertDouble(nVal, sVal);
     664             : 
     665          45 :     mpFormatEntry = new ScColorScaleEntry(nVal, aColor);
     666          45 :     setColorEntryType(sType, mpFormatEntry, sVal, GetScImport());
     667          90 :     pFormat->AddEntry(mpFormatEntry);
     668          45 : }
     669             : 
     670          10 : ScXMLFormattingEntryContext::ScXMLFormattingEntryContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
     671             :                         const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     672             :                         ScColorScaleEntry*& pColorScaleEntry):
     673          10 :     SvXMLImportContext( rImport, nPrfx, rLName )
     674             : {
     675          10 :     OUString sVal;
     676          20 :     OUString sType;
     677             : 
     678          10 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     679          10 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataBarEntryAttrMap();
     680          30 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     681             :     {
     682          20 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     683          40 :         OUString aLocalName;
     684          20 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     685          20 :                     sAttrName, &aLocalName ));
     686          40 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     687             : 
     688          20 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     689             :         {
     690             :             case XML_TOK_DATABARENTRY_TYPE:
     691          10 :                 sType = sValue;
     692          10 :                 break;
     693             :             case XML_TOK_DATABARENTRY_VALUE:
     694          10 :                 sVal = sValue;
     695          10 :                 break;
     696             :             default:
     697           0 :                 break;
     698             :         }
     699          20 :     }
     700             : 
     701          10 :     double nVal = 0;
     702          10 :     if(!sVal.isEmpty())
     703          10 :         sax::Converter::convertDouble(nVal, sVal);
     704             : 
     705          10 :     pColorScaleEntry = new ScColorScaleEntry(nVal, Color());
     706          20 :     setColorEntryType(sType, pColorScaleEntry, sVal, GetScImport());
     707          10 : }
     708             : 
     709             : namespace {
     710             : 
     711           0 : condformat::ScCondFormatDateType getDateFromString(const OUString& rString)
     712             : {
     713           0 :     if(rString == "today")
     714           0 :         return condformat::TODAY;
     715           0 :     else if(rString == "yesterday")
     716           0 :         return condformat::YESTERDAY;
     717           0 :     else if(rString == "tomorrow")
     718           0 :         return condformat::TOMORROW;
     719           0 :     else if(rString == "last-7-days")
     720           0 :         return condformat::LAST7DAYS;
     721           0 :     else if(rString == "this-week")
     722           0 :         return condformat::THISWEEK;
     723           0 :     else if(rString == "last-week")
     724           0 :         return condformat::LASTWEEK;
     725           0 :     else if(rString == "next-week")
     726           0 :         return condformat::NEXTWEEK;
     727           0 :     else if(rString == "this-month")
     728           0 :         return condformat::THISMONTH;
     729           0 :     else if(rString == "last-month")
     730           0 :         return condformat::LASTMONTH;
     731           0 :     else if(rString == "next-month")
     732           0 :         return condformat::NEXTMONTH;
     733           0 :     else if(rString == "this-year")
     734           0 :         return condformat::THISYEAR;
     735           0 :     else if(rString == "last-year")
     736           0 :         return condformat::LASTYEAR;
     737           0 :     else if(rString == "next-year")
     738           0 :         return condformat::NEXTYEAR;
     739             : 
     740             :     SAL_WARN("sc", "unknown date type: " << rString);
     741           0 :     return condformat::TODAY;
     742             : }
     743             : 
     744             : }
     745             : 
     746           0 : ScXMLDateContext::ScXMLDateContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
     747             :                         const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     748             :                         ScConditionalFormat* pFormat ):
     749           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
     750             : {
     751           0 :     OUString sDateType, sStyle;
     752           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     753           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetCondDateAttrMap();
     754           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     755             :     {
     756           0 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     757           0 :         OUString aLocalName;
     758           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     759           0 :                     sAttrName, &aLocalName ));
     760           0 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     761             : 
     762           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     763             :         {
     764             :             case XML_TOK_COND_DATE_VALUE:
     765           0 :                 sDateType = sValue;
     766           0 :                 break;
     767             :             case XML_TOK_COND_DATE_STYLE:
     768           0 :                 sStyle = ScStyleNameConversion::ProgrammaticToDisplayName(sValue, SFX_STYLE_FAMILY_PARA );
     769           0 :                 break;
     770             :             default:
     771           0 :                 break;
     772             :         }
     773           0 :     }
     774             : 
     775           0 :     ScCondDateFormatEntry* pFormatEntry = new ScCondDateFormatEntry(GetScImport().GetDocument());
     776           0 :     pFormatEntry->SetStyleName(sStyle);
     777           0 :     pFormatEntry->SetDateType(getDateFromString(sDateType));
     778           0 :     pFormat->AddEntry(pFormatEntry);
     779             : 
     780           0 : }
     781             : 
     782             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10