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

Generated by: LCOV version 1.11