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

Generated by: LCOV version 1.10