LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlcondformat.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 461 0.0 %
Date: 2014-04-14 Functions: 0 19 0.0 %
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           0 : ScXMLConditionalFormatsContext::ScXMLConditionalFormatsContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
      25             :                         const OUString& rLName):
      26           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
      27             : {
      28           0 :     GetScImport().SetNewCondFormatData();
      29           0 :     GetScImport().GetDocument()->SetCondFormList(new ScConditionalFormatList(), GetScImport().GetTables().GetCurrentSheet());
      30           0 : }
      31             : 
      32           0 : 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           0 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCondFormatsTokenMap();
      38           0 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
      39           0 :     SvXMLImportContext* pContext = NULL;
      40           0 :     switch (nToken)
      41             :     {
      42             :         case XML_TOK_CONDFORMATS_CONDFORMAT:
      43           0 :             pContext = new ScXMLConditionalFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList );
      44           0 :             break;
      45             :     }
      46             : 
      47           0 :     return pContext;
      48             : }
      49             : 
      50           0 : void ScXMLConditionalFormatsContext::EndElement()
      51             : {
      52           0 :     ScDocument* pDoc = GetScImport().GetDocument();
      53             : 
      54           0 :     SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
      55           0 :     ScConditionalFormatList* pCondFormatList = pDoc->GetCondFormList(nTab);
      56           0 :     bool bDeleted = !pCondFormatList->CheckAllEntries();
      57             : 
      58             :     SAL_WARN_IF(bDeleted, "sc", "conditional formats have been deleted because they contained empty range info");
      59           0 : }
      60             : 
      61           0 : 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           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
      64             : {
      65           0 :     OUString sRange;
      66             : 
      67           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      68           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetCondFormatAttrMap();
      69           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      70             :     {
      71           0 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
      72           0 :         OUString aLocalName;
      73           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
      74           0 :                     sAttrName, &aLocalName ));
      75           0 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
      76             : 
      77           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      78             :         {
      79             :             case XML_TOK_CONDFORMAT_TARGET_RANGE:
      80           0 :                 sRange = sValue;
      81           0 :             break;
      82             :             default:
      83           0 :                 break;
      84             :         }
      85           0 :     }
      86             : 
      87           0 :     ScRangeStringConverter::GetRangeListFromString(maRange, sRange, GetScImport().GetDocument(),
      88           0 :             formula::FormulaGrammar::CONV_ODF);
      89             : 
      90           0 :     mpFormat = new ScConditionalFormat(0, GetScImport().GetDocument());
      91           0 :     mpFormat->AddRange(maRange);
      92           0 : }
      93             : 
      94           0 : 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           0 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCondFormatTokenMap();
     100           0 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
     101           0 :     SvXMLImportContext* pContext = NULL;
     102           0 :     switch (nToken)
     103             :     {
     104             :         case XML_TOK_CONDFORMAT_CONDITION:
     105           0 :             pContext = new ScXMLCondContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
     106           0 :             break;
     107             :         case XML_TOK_CONDFORMAT_COLORSCALE:
     108           0 :             pContext = new ScXMLColorScaleFormatContext( GetScImport(), nPrefix, rLocalName, mpFormat );
     109           0 :             break;
     110             :         case XML_TOK_CONDFORMAT_DATABAR:
     111           0 :             pContext = new ScXMLDataBarFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
     112           0 :             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           0 :     return pContext;
     124             : }
     125             : 
     126           0 : void ScXMLConditionalFormatContext::EndElement()
     127             : {
     128           0 :     ScDocument* pDoc = GetScImport().GetDocument();
     129             : 
     130           0 :     SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
     131           0 :     sal_uLong nIndex = pDoc->AddCondFormat(mpFormat, nTab);
     132           0 :     mpFormat->SetKey(nIndex);
     133             : 
     134           0 :     pDoc->AddCondFormatData( mpFormat->GetRange(), nTab, nIndex);
     135           0 : }
     136             : 
     137           0 : ScXMLColorScaleFormatContext::ScXMLColorScaleFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
     138             :                         const OUString& rLName, ScConditionalFormat* pFormat):
     139             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     140           0 :     pColorScaleFormat(NULL)
     141             : {
     142           0 :     pColorScaleFormat = new ScColorScaleFormat(GetScImport().GetDocument());
     143           0 :     pFormat->AddEntry(pColorScaleFormat);
     144           0 : }
     145             : 
     146           0 : 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           0 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetColorScaleTokenMap();
     152           0 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
     153           0 :     SvXMLImportContext* pContext = NULL;
     154           0 :     switch (nToken)
     155             :     {
     156             :         case XML_TOK_COLORSCALE_COLORSCALEENTRY:
     157           0 :             pContext = new ScXMLColorScaleFormatEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pColorScaleFormat );
     158           0 :             break;
     159             :         default:
     160           0 :             break;
     161             :     }
     162             : 
     163           0 :     return pContext;
     164             : }
     165             : 
     166           0 : 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           0 :     mpFormatData(NULL)
     172             : {
     173           0 :     OUString sPositiveColor;
     174           0 :     OUString sNegativeColor;
     175           0 :     OUString sGradient;
     176           0 :     OUString sAxisPosition;
     177           0 :     OUString sShowValue;
     178           0 :     OUString sAxisColor;
     179             : 
     180           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     181           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataBarAttrMap();
     182           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     183             :     {
     184           0 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     185           0 :         OUString aLocalName;
     186           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     187           0 :                     sAttrName, &aLocalName ));
     188           0 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     189             : 
     190           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     191             :         {
     192             :             case XML_TOK_DATABAR_POSITIVE_COLOR:
     193           0 :                 sPositiveColor = sValue;
     194           0 :                 break;
     195             :             case XML_TOK_DATABAR_GRADIENT:
     196           0 :                 sGradient = sValue;
     197           0 :                 break;
     198             :             case XML_TOK_DATABAR_NEGATIVE_COLOR:
     199           0 :                 sNegativeColor = sValue;
     200           0 :                 break;
     201             :             case XML_TOK_DATABAR_AXISPOSITION:
     202           0 :                 sAxisPosition = sValue;
     203           0 :                 break;
     204             :             case XML_TOK_DATABAR_SHOWVALUE:
     205           0 :                 sShowValue = sValue;
     206           0 :                 break;
     207             :             case XML_TOK_DATABAR_AXISCOLOR:
     208           0 :                 sAxisColor = sValue;
     209           0 :                 break;
     210             :             default:
     211           0 :                 break;
     212             :         }
     213           0 :     }
     214             : 
     215           0 :     mpDataBarFormat = new ScDataBarFormat(rImport.GetDocument());
     216           0 :     mpFormatData = new ScDataBarFormatData();
     217           0 :     mpDataBarFormat->SetDataBarData(mpFormatData);
     218           0 :     if(!sGradient.isEmpty())
     219             :     {
     220           0 :         bool bGradient = true;
     221           0 :         sax::Converter::convertBool( bGradient, sGradient);
     222           0 :         mpFormatData->mbGradient = bGradient;
     223             :     }
     224             : 
     225           0 :     if(!sPositiveColor.isEmpty())
     226             :     {
     227           0 :         sal_Int32 nColor = 0;
     228           0 :         sax::Converter::convertColor( nColor, sPositiveColor );
     229           0 :         mpFormatData->maPositiveColor = Color(nColor);
     230             :     }
     231             : 
     232           0 :     if(!sNegativeColor.isEmpty())
     233             :     {
     234             :         // we might check here for 0xff0000 and don't write it
     235           0 :         sal_Int32 nColor = 0;
     236           0 :         sax::Converter::convertColor( nColor, sNegativeColor );
     237           0 :         mpFormatData->mpNegativeColor.reset(new Color(nColor));
     238             :     }
     239             :     else
     240           0 :         mpFormatData->mbNeg = false;
     241             : 
     242           0 :     if(!sAxisPosition.isEmpty())
     243             :     {
     244           0 :         if(sAxisPosition == "middle")
     245           0 :             mpFormatData->meAxisPosition = databar::MIDDLE;
     246           0 :         else if (sAxisPosition == "none")
     247           0 :             mpFormatData->meAxisPosition = databar::NONE;
     248             :     }
     249             : 
     250           0 :     if(!sAxisColor.isEmpty())
     251             :     {
     252           0 :         sal_Int32 nColor = 0;
     253           0 :         sax::Converter::convertColor( nColor, sAxisColor );
     254           0 :         mpFormatData->maAxisColor = Color(nColor);
     255             :     }
     256             : 
     257           0 :     if(!sShowValue.isEmpty())
     258             :     {
     259           0 :         bool bShowValue = true;
     260           0 :         sax::Converter::convertBool( bShowValue, sShowValue );
     261           0 :         mpFormatData->mbOnlyBar = !bShowValue;
     262             :     }
     263             : 
     264           0 :     pFormat->AddEntry(mpDataBarFormat);
     265           0 : }
     266             : 
     267           0 : 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           0 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetFormattingTokenMap();
     273           0 :     sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName);
     274           0 :     SvXMLImportContext* pContext = NULL;
     275           0 :     switch (nToken)
     276             :     {
     277             :         case XML_TOK_FORMATTING_ENTRY:
     278             :         case XML_TOK_DATABAR_DATABARENTRY:
     279             :         {
     280           0 :             ScColorScaleEntry* pEntry(0);
     281           0 :             pContext = new ScXMLFormattingEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry );
     282           0 :             if(mpFormatData->mpLowerLimit)
     283             :             {
     284           0 :                 mpFormatData->mpUpperLimit.reset(pEntry);
     285             :             }
     286             :             else
     287             :             {
     288           0 :                 mpFormatData->mpLowerLimit.reset(pEntry);
     289             :             }
     290             :         }
     291           0 :         break;
     292             :         default:
     293           0 :             break;
     294             :     }
     295             : 
     296           0 :     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           0 : void GetConditionData(const OUString& rValue, ScConditionMode& eMode, OUString& rExpr1, OUString& rExpr2)
     386             : {
     387           0 :     if(rValue.startsWith("unique"))
     388             :     {
     389           0 :         eMode = SC_COND_NOTDUPLICATE;
     390             :     }
     391           0 :     else if(rValue.startsWith("duplicate"))
     392             :     {
     393           0 :         eMode = SC_COND_DUPLICATE;
     394             :     }
     395           0 :     else if(rValue.startsWith("between"))
     396             :     {
     397           0 :         const sal_Unicode* pStr = rValue.getStr();
     398           0 :         const sal_Unicode* pStart = pStr + 8;
     399           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     400           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ',');
     401           0 :         rExpr2 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     402           0 :         eMode = SC_COND_BETWEEN;
     403             :     }
     404           0 :     else if(rValue.startsWith("not-between"))
     405             :     {
     406           0 :         const sal_Unicode* pStr = rValue.getStr();
     407           0 :         const sal_Unicode* pStart = pStr + 12;
     408           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     409           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ',');
     410           0 :         rExpr2 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     411           0 :         eMode = SC_COND_NOTBETWEEN;
     412             :     }
     413           0 :     else if(rValue.startsWith("<="))
     414             :     {
     415           0 :         rExpr1 = rValue.copy(2);
     416           0 :         eMode = SC_COND_EQLESS;
     417             :     }
     418           0 :     else if(rValue.startsWith(">="))
     419             :     {
     420           0 :         rExpr1 = rValue.copy(2);
     421           0 :         eMode = SC_COND_EQGREATER;
     422             :     }
     423           0 :     else if(rValue.startsWith("!="))
     424             :     {
     425           0 :         rExpr1 = rValue.copy(2);
     426           0 :         eMode = SC_COND_NOTEQUAL;
     427             :     }
     428           0 :     else if(rValue.startsWith("<"))
     429             :     {
     430           0 :         rExpr1 = rValue.copy(1);
     431           0 :         eMode = SC_COND_LESS;
     432             :     }
     433           0 :     else if(rValue.startsWith("="))
     434             :     {
     435           0 :         rExpr1 = rValue.copy(1);
     436           0 :         eMode = SC_COND_EQUAL;
     437             :     }
     438           0 :     else if(rValue.startsWith(">"))
     439             :     {
     440           0 :         rExpr1 = rValue.copy(1);
     441           0 :         eMode = SC_COND_GREATER;
     442             :     }
     443           0 :     else if(rValue.startsWith("formula-is"))
     444             :     {
     445           0 :         const sal_Unicode* pStr = rValue.getStr();
     446           0 :         const sal_Unicode* pStart = pStr + 11;
     447           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     448           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     449           0 :         eMode = SC_COND_DIRECT;
     450             :     }
     451           0 :     else if(rValue.startsWith("top-elements"))
     452             :     {
     453           0 :         const sal_Unicode* pStr = rValue.getStr();
     454           0 :         const sal_Unicode* pStart = pStr + 13;
     455           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     456           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     457           0 :         eMode = SC_COND_TOP10;
     458             :     }
     459           0 :     else if(rValue.startsWith("bottom-elements"))
     460             :     {
     461           0 :         const sal_Unicode* pStr = rValue.getStr();
     462           0 :         const sal_Unicode* pStart = pStr + 16;
     463           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     464           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     465           0 :         eMode = SC_COND_BOTTOM10;
     466             :     }
     467           0 :     else if(rValue.startsWith("top-percent"))
     468             :     {
     469           0 :         const sal_Unicode* pStr = rValue.getStr();
     470           0 :         const sal_Unicode* pStart = pStr + 12;
     471           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     472           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     473           0 :         eMode = SC_COND_TOP_PERCENT;
     474             :     }
     475           0 :     else if(rValue.startsWith("bottom-percent"))
     476             :     {
     477           0 :         const sal_Unicode* pStr = rValue.getStr();
     478           0 :         const sal_Unicode* pStart = pStr + 15;
     479           0 :         const sal_Unicode* pEnd = pStr + rValue.getLength();
     480           0 :         rExpr1 = ScXMLConditionHelper::getExpression( pStart, pEnd, ')');
     481           0 :         eMode = SC_COND_BOTTOM_PERCENT;
     482             :     }
     483           0 :     else if(rValue.startsWith("above-average"))
     484             :     {
     485           0 :         eMode = SC_COND_ABOVE_AVERAGE;
     486             :     }
     487           0 :     else if(rValue.startsWith("below-average"))
     488             :     {
     489           0 :         eMode = SC_COND_BELOW_AVERAGE;
     490             :     }
     491           0 :     else if(rValue.startsWith("above-equal-average"))
     492             :     {
     493           0 :         eMode = SC_COND_ABOVE_EQUAL_AVERAGE;
     494             :     }
     495           0 :     else if(rValue.startsWith("below-equal-average"))
     496             :     {
     497           0 :         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           0 : }
     542             : 
     543             : }
     544             : 
     545           0 : 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           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
     549             : {
     550           0 :     OUString sExpression;
     551           0 :     OUString sStyle;
     552           0 :     OUString sAddress;
     553             : 
     554           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     555           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetConditionAttrMap();
     556           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     557             :     {
     558           0 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     559           0 :         OUString aLocalName;
     560           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     561           0 :                     sAttrName, &aLocalName ));
     562           0 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     563             : 
     564           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     565             :         {
     566             :             case XML_TOK_CONDITION_VALUE:
     567           0 :                 sExpression = sValue;
     568           0 :                 break;
     569             :             case XML_TOK_CONDITION_APPLY_STYLE_NAME:
     570           0 :                 sStyle = ScStyleNameConversion::ProgrammaticToDisplayName(sValue, SFX_STYLE_FAMILY_PARA );
     571           0 :                 break;
     572             :             case XML_TOK_CONDITION_BASE_CELL_ADDRESS:
     573           0 :                 sAddress = sValue;
     574           0 :                 break;
     575             :             default:
     576           0 :                 break;
     577             :         }
     578           0 :     }
     579             : 
     580           0 :     OUString aExpr1;
     581           0 :     OUString aExpr2;
     582             :     ScConditionMode eMode;
     583           0 :     GetConditionData(sExpression, eMode, aExpr1, aExpr2);
     584             : 
     585           0 :     ScCondFormatEntry* pFormatEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, GetScImport().GetDocument(), ScAddress(), sStyle,
     586           0 :                                                         OUString(), OUString(), formula::FormulaGrammar::GRAM_ODFF, formula::FormulaGrammar::GRAM_ODFF);
     587           0 :     pFormatEntry->SetSrcString(sAddress);
     588             : 
     589           0 :     pFormat->AddEntry(pFormatEntry);
     590           0 : }
     591             : 
     592             : namespace {
     593             : 
     594           0 : void setColorEntryType(const OUString& rType, ScColorScaleEntry* pEntry, const OUString& rFormula,
     595             :         ScXMLImport& rImport)
     596             : {
     597           0 :     if(rType == "minimum")
     598           0 :         pEntry->SetType(COLORSCALE_MIN);
     599           0 :     else if(rType == "maximum")
     600           0 :         pEntry->SetType(COLORSCALE_MAX);
     601           0 :     else if(rType == "percentile")
     602           0 :         pEntry->SetType(COLORSCALE_PERCENTILE);
     603           0 :     else if(rType == "percent")
     604           0 :         pEntry->SetType(COLORSCALE_PERCENT);
     605           0 :     else if(rType == "formula")
     606             :     {
     607           0 :         pEntry->SetType(COLORSCALE_FORMULA);
     608             :         //position does not matter, only table is important
     609           0 :         pEntry->SetFormula(rFormula, rImport.GetDocument(), ScAddress(0,0,rImport.GetTables().GetCurrentSheet()), formula::FormulaGrammar::GRAM_ODFF);
     610             :     }
     611           0 :     else if(rType == "auto-minimum")
     612           0 :         pEntry->SetType(COLORSCALE_AUTO);
     613           0 :     else if(rType == "auto-maximum")
     614           0 :         pEntry->SetType(COLORSCALE_AUTO);
     615           0 : }
     616             : 
     617             : }
     618             : 
     619           0 : 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           0 :     mpFormatEntry( NULL )
     624             : {
     625           0 :     double nVal = 0;
     626           0 :     Color aColor;
     627             : 
     628           0 :     OUString sType;
     629           0 :     OUString sVal;
     630           0 :     OUString sColor;
     631             : 
     632           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     633           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetColorScaleEntryAttrMap();
     634           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     635             :     {
     636           0 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     637           0 :         OUString aLocalName;
     638           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     639           0 :                     sAttrName, &aLocalName ));
     640           0 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     641             : 
     642           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     643             :         {
     644             :             case XML_TOK_COLORSCALEENTRY_TYPE:
     645           0 :                 sType = sValue;
     646           0 :                 break;
     647             :             case XML_TOK_COLORSCALEENTRY_VALUE:
     648           0 :                 sVal = sValue;
     649           0 :                 break;
     650             :             case XML_TOK_COLORSCALEENTRY_COLOR:
     651           0 :                 sColor = sValue;
     652           0 :                 break;
     653             :             default:
     654           0 :                 break;
     655             :         }
     656           0 :     }
     657             : 
     658             :     sal_Int32 nColor;
     659           0 :     sax::Converter::convertColor(nColor, sColor);
     660           0 :     aColor = Color(nColor);
     661             : 
     662           0 :     if(!sVal.isEmpty())
     663           0 :         sax::Converter::convertDouble(nVal, sVal);
     664             : 
     665           0 :     mpFormatEntry = new ScColorScaleEntry(nVal, aColor);
     666           0 :     setColorEntryType(sType, mpFormatEntry, sVal, GetScImport());
     667           0 :     pFormat->AddEntry(mpFormatEntry);
     668           0 : }
     669             : 
     670           0 : 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           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
     674             : {
     675           0 :     OUString sVal;
     676           0 :     OUString sType;
     677             : 
     678           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     679           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataBarEntryAttrMap();
     680           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     681             :     {
     682           0 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     683           0 :         OUString aLocalName;
     684           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     685           0 :                     sAttrName, &aLocalName ));
     686           0 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     687             : 
     688           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     689             :         {
     690             :             case XML_TOK_DATABARENTRY_TYPE:
     691           0 :                 sType = sValue;
     692           0 :                 break;
     693             :             case XML_TOK_DATABARENTRY_VALUE:
     694           0 :                 sVal = sValue;
     695           0 :                 break;
     696             :             default:
     697           0 :                 break;
     698             :         }
     699           0 :     }
     700             : 
     701           0 :     double nVal = 0;
     702           0 :     if(!sVal.isEmpty())
     703           0 :         sax::Converter::convertDouble(nVal, sVal);
     704             : 
     705           0 :     pColorScaleEntry = new ScColorScaleEntry(nVal, Color());
     706           0 :     setColorEntryType(sType, pColorScaleEntry, sVal, GetScImport());
     707           0 : }
     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