LCOV - code coverage report
Current view: top level - sc/source/filter/oox - extlstcontext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 108 119 90.8 %
Date: 2015-06-13 12:38:46 Functions: 19 19 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 "extlstcontext.hxx"
      11             : #include "worksheethelper.hxx"
      12             : #include <oox/core/contexthandler.hxx>
      13             : #include "colorscale.hxx"
      14             : #include "condformatbuffer.hxx"
      15             : #include "condformatcontext.hxx"
      16             : #include "document.hxx"
      17             : 
      18             : #include "rangeutl.hxx"
      19             : 
      20             : using ::oox::core::ContextHandlerRef;
      21             : 
      22             : namespace oox {
      23             : namespace xls {
      24             : 
      25          17 : ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase& rFragment, ScDataBarFormatData* pTarget ):
      26             :     WorksheetContextBase( rFragment ),
      27             :     mpTarget( pTarget ),
      28          17 :     mbFirstEntry(true)
      29             : {
      30          17 : }
      31             : 
      32          89 : ContextHandlerRef ExtCfRuleContext::onCreateContext( sal_Int32 , const AttributeList& )
      33             : {
      34          89 :     return this;
      35             : }
      36             : 
      37         106 : void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
      38             : {
      39         106 :     switch( getCurrentElement() )
      40             :     {
      41             :         case XLS14_TOKEN( dataBar ):
      42             :         {
      43          17 :             ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
      44          17 :             xRule->importDataBar( rAttribs );
      45          17 :             break;
      46             :         }
      47             :         case XLS14_TOKEN( negativeFillColor ):
      48             :         {
      49          17 :             ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
      50          17 :             xRule->importNegativeFillColor( rAttribs );
      51          17 :             break;
      52             :         }
      53             :         case XLS14_TOKEN( axisColor ):
      54             :         {
      55          17 :             ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
      56          17 :             xRule->importAxisColor( rAttribs );
      57          17 :             break;
      58             :         }
      59             :         case XLS14_TOKEN( cfvo ):
      60             :         {
      61          34 :             ExtCfDataBarRuleRef xRule = getCondFormats().createExtCfDataBarRule(mpTarget);
      62          34 :             xRule->importCfvo( rAttribs );
      63          34 :             xRule->getModel().mbIsLower = mbFirstEntry;
      64          34 :             mbFirstEntry = false;
      65          34 :             break;
      66             :         }
      67             :         default:
      68          21 :             break;
      69             :     }
      70         106 : }
      71             : 
      72          22 : ExtConditionalFormattingContext::ExtConditionalFormattingContext(WorksheetContextBase& rFragment):
      73             :     WorksheetContextBase(rFragment),
      74          22 :     mpCurrentRule(NULL)
      75             : {
      76          22 : }
      77             : 
      78          44 : ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nElement, const AttributeList& rAttribs)
      79             : {
      80          44 :     if (mpCurrentRule)
      81             :     {
      82           5 :         ScFormatEntry& rFormat = *maEntries.rbegin();
      83             :         assert(rFormat.GetType() == condformat::ICONSET);
      84           5 :         ScIconSetFormat& rIconSet = static_cast<ScIconSetFormat&>(rFormat);
      85           5 :         ScDocument* pDoc = &getScDocument();
      86           5 :         SCTAB nTab = getSheetIndex();
      87           5 :         ScAddress aPos(0, 0, nTab);
      88           5 :         mpCurrentRule->SetData(&rIconSet, pDoc, aPos);
      89           5 :         delete mpCurrentRule;
      90           5 :         mpCurrentRule = NULL;
      91             :     }
      92          44 :     if (nElement == XLS14_TOKEN(cfRule))
      93             :     {
      94          22 :         OUString aType = rAttribs.getString(XML_type, OUString());
      95          22 :         OUString aId = rAttribs.getString(XML_id, OUString());
      96          22 :         if (aType == "dataBar")
      97             :         {
      98             :             // an ext entry does not need to have an existing corresponding entry
      99          17 :             ExtLst::const_iterator aExt = getExtLst().find( aId );
     100          17 :             if(aExt == getExtLst().end())
     101           0 :                 return NULL;
     102             : 
     103          17 :             ScDataBarFormatData* pInfo = aExt->second;
     104          17 :             if (!pInfo)
     105             :             {
     106           0 :                 return NULL;
     107             :             }
     108          17 :             return new ExtCfRuleContext( *this, pInfo );
     109             :         }
     110           5 :         else if (aType == "iconSet")
     111             :         {
     112           5 :             ScDocument* pDoc = &getScDocument();
     113           5 :             mpCurrentRule = new IconSetRule(*this);
     114           5 :             ScIconSetFormat* pIconSet = new ScIconSetFormat(pDoc);
     115           5 :             maEntries.push_back(pIconSet);
     116           5 :             return new IconSetContext(*this, mpCurrentRule);
     117             :         }
     118             :         else
     119             :         {
     120             :             SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType);
     121           0 :         }
     122             :     }
     123          22 :     else if (nElement == XM_TOKEN(sqref))
     124             :     {
     125          22 :         return this;
     126             :     }
     127             : 
     128           0 :     return NULL;
     129             : }
     130             : 
     131          44 : void ExtConditionalFormattingContext::onStartElement(const AttributeList& /*rAttribs*/)
     132             : {
     133          44 :     switch (getCurrentElement())
     134             :     {
     135             :         case XM_TOKEN(sqref):
     136             :         {
     137             :         }
     138          22 :         break;
     139             :     }
     140          44 : }
     141             : 
     142          22 : void ExtConditionalFormattingContext::onCharacters(const OUString& rCharacters)
     143             : {
     144          22 :     aChars = rCharacters;
     145          22 : }
     146             : 
     147          44 : void ExtConditionalFormattingContext::onEndElement()
     148             : {
     149          44 :     switch (getCurrentElement())
     150             :     {
     151             :         case XM_TOKEN(sqref):
     152             :         {
     153          22 :             ScRangeList aRange;
     154          22 :             ScDocument* pDoc = &getScDocument();
     155          22 :             bool bSuccess = ScRangeStringConverter::GetRangeListFromString(aRange, aChars, pDoc, formula::FormulaGrammar::CONV_XL_OOX);
     156          22 :             if (!bSuccess || aRange.empty())
     157           0 :                 break;
     158             : 
     159          22 :             SCTAB nTab = getSheetIndex();
     160          44 :             for (size_t i = 0; i < aRange.size(); ++i)
     161             :             {
     162          22 :                 aRange[i]->aStart.SetTab(nTab);
     163          22 :                 aRange[i]->aEnd.SetTab(nTab);
     164             :             }
     165             : 
     166          22 :             boost::ptr_vector<ExtCfCondFormat>& rExtFormats =  getCondFormats().importExtCondFormat();
     167          22 :             rExtFormats.push_back(new ExtCfCondFormat(aRange, maEntries));
     168             :         }
     169          22 :         break;
     170             :         case XLS14_TOKEN(cfRule):
     171           0 :             if (mpCurrentRule)
     172             :             {
     173             :             }
     174           0 :         break;
     175             :         default:
     176          22 :         break;
     177             :     }
     178          44 : }
     179             : 
     180          17 : ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase& rFragment, ScDataBarFormatData* pTarget ):
     181             :     WorksheetContextBase(rFragment),
     182          17 :     mpTarget(pTarget)
     183             : {
     184          17 : }
     185             : 
     186          34 : ContextHandlerRef ExtLstLocalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
     187             : {
     188          34 :     switch( getCurrentElement() )
     189             :     {
     190             :         case XLS_TOKEN( extLst ):
     191          17 :             if(nElement == XLS_TOKEN( ext ))
     192          17 :                 return this;
     193             :             else
     194           0 :                 return 0;
     195             :             break;
     196             :         case XLS_TOKEN( ext ):
     197          17 :             if (nElement == XLS14_TOKEN( id ))
     198          17 :                 return this;
     199             :             else
     200           0 :                 return 0;
     201             :     }
     202           0 :     return 0;
     203             : }
     204             : 
     205          51 : void ExtLstLocalContext::onStartElement( const AttributeList& )
     206             : {
     207          51 :     switch( getCurrentElement() )
     208             :     {
     209             :         case XLS14_TOKEN( id ):
     210          17 :         break;
     211             :     }
     212          51 : }
     213             : 
     214          17 : void ExtLstLocalContext::onCharacters( const OUString& rChars )
     215             : {
     216          17 :     if (getCurrentElement() == XLS14_TOKEN( id ))
     217             :     {
     218          17 :         getExtLst().insert( std::pair< OUString, ScDataBarFormatData*>(rChars, mpTarget) );
     219             :     }
     220          17 : }
     221             : 
     222           7 : ExtGlobalContext::ExtGlobalContext( WorksheetContextBase& rFragment ):
     223           7 :     WorksheetContextBase(rFragment)
     224             : {
     225           7 : }
     226             : 
     227          29 : ContextHandlerRef ExtGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
     228             : {
     229          29 :     if (nElement == XLS14_TOKEN(conditionalFormatting))
     230          22 :         return new ExtConditionalFormattingContext(*this);
     231             : 
     232           7 :     return this;
     233             : }
     234             : 
     235          14 : void ExtGlobalContext::onStartElement( const AttributeList& /*rAttribs*/ )
     236             : {
     237          14 : }
     238             : 
     239           7 : ExtLstGlobalContext::ExtLstGlobalContext( WorksheetFragment& rFragment ):
     240           7 :     WorksheetContextBase(rFragment)
     241             : {
     242           7 : }
     243             : 
     244           7 : ContextHandlerRef ExtLstGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
     245             : {
     246           7 :     if (nElement == XLS_TOKEN( ext ))
     247           7 :         return new ExtGlobalContext( *this );
     248             : 
     249           0 :     return this;
     250             : }
     251             : 
     252             : } //namespace oox
     253          30 : } //namespace xls
     254             : 
     255             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11