LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/oox - extlstcontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 118 0.8 %
Date: 2012-12-27 Functions: 2 19 10.5 %
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 "extlstcontext.hxx"
      30             : #include "worksheethelper.hxx"
      31             : #include <oox/core/contexthandler.hxx>
      32             : #include "colorscale.hxx"
      33             : 
      34             : using ::oox::core::ContextHandlerRef;
      35             : 
      36             : namespace oox {
      37             : namespace xls {
      38             : 
      39           0 : ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase& rFragment, void* pTarget ):
      40             :     WorksheetContextBase( rFragment ),
      41             :     mpTarget( pTarget ),
      42           0 :     mbFirstEntry(true)
      43             : {
      44           0 : }
      45             : 
      46           0 : ContextHandlerRef ExtCfRuleContext::onCreateContext( sal_Int32 , const AttributeList& )
      47             : {
      48           0 :     return this;
      49             : }
      50             : 
      51           0 : void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
      52             : {
      53           0 :     switch( getCurrentElement() )
      54             :     {
      55             :         case XLS_EXT_TOKEN( dataBar ):
      56           0 :             importDataBar( rAttribs );
      57           0 :             break;
      58             :         case XLS_EXT_TOKEN( negativeFillColor ):
      59           0 :             importNegativeFillColor( rAttribs );
      60           0 :             break;
      61             :         case XLS_EXT_TOKEN( axisColor ):
      62           0 :             importAxisColor( rAttribs );
      63           0 :             break;
      64             :         case XLS_EXT_TOKEN( cfvo ):
      65           0 :             importCfvo( rAttribs );
      66           0 :             break;
      67             : 
      68             :         default:
      69           0 :             break;
      70             :     }
      71           0 : }
      72             : 
      73           0 : void ExtCfRuleContext::importDataBar( const AttributeList& rAttribs )
      74             : {
      75           0 :     ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
      76           0 :     pDataBar->mbGradient = rAttribs.getBool( XML_gradient, true );
      77             : 
      78           0 :     rtl::OUString aAxisPosition = rAttribs.getString( XML_axisPosition, "automatic" );
      79           0 :     if( aAxisPosition == "none" )
      80           0 :         pDataBar->meAxisPosition = databar::NONE;
      81           0 :     else if( aAxisPosition == "middle" )
      82           0 :         pDataBar->meAxisPosition = databar::MIDDLE;
      83             :     else
      84           0 :         pDataBar->meAxisPosition = databar::AUTOMATIC;
      85             : 
      86           0 :     pDataBar->mbNeg = !rAttribs.getBool( XML_negativeBarColorSameAsPositive, false );
      87           0 : }
      88             : 
      89             : namespace {
      90             : 
      91           0 : ::Color RgbToRgbComponents( sal_Int32 nRgb )
      92             : {
      93           0 :     sal_Int32 ornR = (nRgb >> 16) & 0xFF;
      94           0 :     sal_Int32 ornG = (nRgb >> 8) & 0xFF;
      95           0 :     sal_Int32 ornB = nRgb & 0xFF;
      96             : 
      97           0 :     return ::Color(ornR, ornG, ornB);
      98             : }
      99             : 
     100             : }
     101             : 
     102           0 : void ExtCfRuleContext::importAxisColor( const AttributeList& rAttribs )
     103             : {
     104           0 :     ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
     105             : 
     106           0 :     sal_Int32 nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
     107           0 :     ::Color aColor = RgbToRgbComponents(nColor);
     108           0 :     pDataBar->maAxisColor = aColor;
     109           0 : }
     110             : 
     111           0 : void ExtCfRuleContext::importNegativeFillColor( const AttributeList& rAttribs )
     112             : {
     113           0 :     sal_Int32 nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
     114           0 :     ::Color aColor = RgbToRgbComponents(nColor);
     115           0 :     ::Color* pColor = new Color(aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue());
     116           0 :     static_cast<ScDataBarFormatData*>(mpTarget)->mpNegativeColor.reset(pColor);
     117           0 : }
     118             : 
     119           0 : void ExtCfRuleContext::importCfvo( const AttributeList& rAttribs )
     120             : {
     121           0 :     ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
     122           0 :     ScColorScaleEntry* pEntry = NULL;
     123           0 :     if(mbFirstEntry)
     124           0 :         pEntry = pDataBar->mpLowerLimit.get();
     125             :     else
     126           0 :         pEntry = pDataBar->mpUpperLimit.get();
     127             : 
     128           0 :     rtl::OUString aColorScaleType = rAttribs.getString( XML_type, rtl::OUString() );
     129           0 :     if(aColorScaleType == "min")
     130           0 :         pEntry->SetType(COLORSCALE_MIN);
     131           0 :     else if (aColorScaleType == "max")
     132           0 :         pEntry->SetType(COLORSCALE_MAX);
     133           0 :     else if (aColorScaleType == "autoMin")
     134           0 :         pEntry->SetType(COLORSCALE_AUTO);
     135           0 :     else if (aColorScaleType == "autoMax")
     136           0 :         pEntry->SetType(COLORSCALE_AUTO);
     137           0 :     else if (aColorScaleType == "percentile")
     138           0 :         pEntry->SetType(COLORSCALE_PERCENTILE);
     139           0 :     else if (aColorScaleType == "percent")
     140           0 :         pEntry->SetType(COLORSCALE_PERCENT);
     141           0 :     else if (aColorScaleType == "formula")
     142           0 :         pEntry->SetType(COLORSCALE_FORMULA);
     143             : 
     144           0 :     mbFirstEntry = false;
     145           0 : }
     146             : 
     147           0 : ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase& rFragment, void* pTarget ):
     148             :     WorksheetContextBase(rFragment),
     149           0 :     mpTarget(pTarget)
     150             : {
     151           0 : }
     152             : 
     153           0 : ContextHandlerRef ExtLstLocalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
     154             : {
     155           0 :     switch( getCurrentElement() )
     156             :     {
     157             :         case XLS_TOKEN( extLst ):
     158           0 :             if(nElement == XLS_TOKEN( ext ))
     159           0 :                 return this;
     160             :             else
     161           0 :                 return 0;
     162             :             break;
     163             :         case XLS_TOKEN( ext ):
     164           0 :             if (nElement == XLS_EXT_TOKEN( id ))
     165           0 :                 return this;
     166             :             else
     167           0 :                 return 0;
     168             :     }
     169           0 :     return 0;
     170             : }
     171             : 
     172           0 : void ExtLstLocalContext::onStartElement( const AttributeList& )
     173             : {
     174           0 :     switch( getCurrentElement() )
     175             :     {
     176             :         case XLS_EXT_TOKEN( id ):
     177           0 :         break;
     178             :     }
     179           0 : }
     180             : 
     181           0 : void ExtLstLocalContext::onCharacters( const rtl::OUString& rChars )
     182             : {
     183           0 :     if (getCurrentElement() == XLS_EXT_TOKEN( id ))
     184             :     {
     185           0 :         getExtLst().insert( std::pair< rtl::OUString, void*>(rChars, mpTarget) );
     186             :     }
     187           0 : }
     188             : 
     189           0 : ExtGlobalContext::ExtGlobalContext( WorksheetContextBase& rFragment ):
     190           0 :     WorksheetContextBase(rFragment)
     191             : {
     192           0 : }
     193             : 
     194           0 : ContextHandlerRef ExtGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     195             : {
     196           0 :     if(!rAttribs.hasAttribute( XML_id))
     197           0 :         return this;
     198             :     else
     199             :     {
     200           0 :         if(nElement == XLS_EXT_TOKEN( cfRule ))
     201             :         {
     202           0 :             rtl::OUString aId = rAttribs.getString( XML_id, rtl::OUString() );
     203             : 
     204             :             // an ext entrie does not need to have an existing corresponding entry
     205           0 :             ExtLst::const_iterator aExt = getExtLst().find( aId );
     206           0 :             if(aExt == getExtLst().end())
     207           0 :                 return NULL;
     208             : 
     209           0 :             void* pInfo = aExt->second;
     210           0 :             if (!pInfo)
     211             :             {
     212           0 :                 return NULL;
     213             :             }
     214           0 :             return new ExtCfRuleContext( *this, pInfo );
     215             :         }
     216             :         else
     217           0 :             return this;
     218             :     }
     219             : }
     220             : 
     221           0 : void ExtGlobalContext::onStartElement( const AttributeList& rAttribs )
     222             : {
     223           0 :     if(rAttribs.hasAttribute( XML_id ))
     224             :     {
     225           0 :         rtl::OUString aId = rAttribs.getString( XML_id, rtl::OUString() );
     226             :     }
     227             : 
     228           0 :     if(rAttribs.hasAttribute( XML_uri ))
     229             :     {
     230           0 :         rtl::OUString aUri = rAttribs.getString( XML_uri, rtl::OUString() );
     231             :     }
     232           0 : }
     233             : 
     234           0 : ExtLstGlobalContext::ExtLstGlobalContext( WorksheetFragment& rFragment ):
     235           0 :     WorksheetContextBase(rFragment)
     236             : {
     237           0 : }
     238             : 
     239           0 : ContextHandlerRef ExtLstGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
     240             : {
     241           0 :     if (nElement == XLS_TOKEN( ext ))
     242           0 :         return new ExtGlobalContext( *this );
     243             : 
     244           0 :     return this;
     245             : }
     246             : 
     247             : } //namespace oox
     248           9 : } //namespace xls
     249             : 
     250             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10