LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - XMLConsolidationContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 60 0.0 %
Date: 2012-12-27 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : 
      22             : 
      23             : //___________________________________________________________________
      24             : #include "XMLConsolidationContext.hxx"
      25             : #include "document.hxx"
      26             : #include "rangeutl.hxx"
      27             : #include "xmlimprt.hxx"
      28             : #include "XMLConverter.hxx"
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include <xmloff/xmltoken.hxx>
      31             : 
      32             : using ::rtl::OUString;
      33             : using namespace ::com::sun::star;
      34             : using namespace xmloff::token;
      35             : 
      36             : 
      37             : //___________________________________________________________________
      38             : 
      39           0 : ScXMLConsolidationContext::ScXMLConsolidationContext(
      40             :         ScXMLImport& rImport,
      41             :         sal_uInt16 nPrfx,
      42             :         const OUString& rLName,
      43             :         const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
      44             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      45             :     eFunction( SUBTOTAL_FUNC_NONE ),
      46             :     bLinkToSource( false ),
      47           0 :     bTargetAddr(false)
      48             : {
      49           0 :     ScXMLImport::MutexGuard aGuard(GetScImport());
      50           0 :     if( !xAttrList.is() ) return;
      51             : 
      52           0 :     sal_Int16               nAttrCount      = xAttrList->getLength();
      53           0 :     const SvXMLTokenMap&    rAttrTokenMap   = GetScImport().GetConsolidationAttrTokenMap();
      54             : 
      55           0 :     for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
      56             :     {
      57           0 :         const rtl::OUString& sAttrName  (xAttrList->getNameByIndex( nIndex ));
      58           0 :         const rtl::OUString& sValue     (xAttrList->getValueByIndex( nIndex ));
      59           0 :         OUString aLocalName;
      60           0 :         sal_uInt16 nPrefix      = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
      61             : 
      62           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      63             :         {
      64             :             case XML_TOK_CONSOLIDATION_ATTR_FUNCTION:
      65           0 :                 eFunction = ScXMLConverter::GetSubTotalFuncFromString( sValue );
      66           0 :             break;
      67             :             case XML_TOK_CONSOLIDATION_ATTR_SOURCE_RANGES:
      68           0 :                 sSourceList = sValue;
      69           0 :             break;
      70             :             case XML_TOK_CONSOLIDATION_ATTR_TARGET_ADDRESS:
      71             :                 {
      72           0 :                     sal_Int32 nOffset(0);
      73             :                     bTargetAddr = ScRangeStringConverter::GetAddressFromString(
      74           0 :                         aTargetAddr, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
      75             :                 }
      76           0 :                 break;
      77             :             case XML_TOK_CONSOLIDATION_ATTR_USE_LABEL:
      78           0 :                 sUseLabel = sValue;
      79           0 :             break;
      80             :             case XML_TOK_CONSOLIDATION_ATTR_LINK_TO_SOURCE:
      81           0 :                 bLinkToSource = IsXMLToken(sValue, XML_TRUE);
      82           0 :             break;
      83             :         }
      84           0 :     }
      85             : }
      86             : 
      87           0 : ScXMLConsolidationContext::~ScXMLConsolidationContext()
      88             : {
      89           0 : }
      90             : 
      91           0 : SvXMLImportContext *ScXMLConsolidationContext::CreateChildContext(
      92             :         sal_uInt16 nPrefix,
      93             :         const OUString& rLName,
      94             :         const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
      95             : {
      96           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );
      97             : }
      98             : 
      99           0 : void ScXMLConsolidationContext::EndElement()
     100             : {
     101           0 :     if (bTargetAddr)
     102             :     {
     103           0 :         ScConsolidateParam aConsParam;
     104           0 :         aConsParam.nCol = aTargetAddr.Col();
     105           0 :         aConsParam.nRow = aTargetAddr.Row();
     106           0 :         aConsParam.nTab = aTargetAddr.Tab();
     107           0 :         aConsParam.eFunction = eFunction;
     108             : 
     109           0 :         sal_uInt16 nCount = (sal_uInt16) Min( ScRangeStringConverter::GetTokenCount( sSourceList ), (sal_Int32)0xFFFF );
     110           0 :         ScArea** ppAreas = nCount ? new ScArea*[ nCount ] : NULL;
     111           0 :         if( ppAreas )
     112             :         {
     113           0 :             sal_Int32 nOffset = 0;
     114             :             sal_uInt16 nIndex;
     115           0 :             for( nIndex = 0; nIndex < nCount; ++nIndex )
     116             :             {
     117           0 :                 ppAreas[ nIndex ] = new ScArea;
     118           0 :                 if ( !ScRangeStringConverter::GetAreaFromString(
     119           0 :                     *ppAreas[ nIndex ], sSourceList, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
     120             :                 {
     121             :                     //! handle error
     122             :                 }
     123             :             }
     124             : 
     125           0 :             aConsParam.SetAreas( ppAreas, nCount );
     126             : 
     127             :             // array is copied in SetAreas
     128           0 :             for( nIndex = 0; nIndex < nCount; ++nIndex )
     129           0 :                 delete ppAreas[nIndex];
     130           0 :             delete[] ppAreas;
     131             :         }
     132             : 
     133           0 :         aConsParam.bByCol = aConsParam.bByRow = false;
     134           0 :         if( IsXMLToken(sUseLabel, XML_COLUMN ) )
     135           0 :             aConsParam.bByCol = true;
     136           0 :         else if( IsXMLToken( sUseLabel, XML_ROW ) )
     137           0 :             aConsParam.bByRow = true;
     138           0 :         else if( IsXMLToken( sUseLabel, XML_BOTH ) )
     139           0 :             aConsParam.bByCol = aConsParam.bByRow = true;
     140             : 
     141           0 :         aConsParam.bReferenceData = bLinkToSource;
     142             : 
     143           0 :         ScDocument* pDoc = GetScImport().GetDocument();
     144           0 :         if( pDoc )
     145           0 :             pDoc->SetConsolidateDlgData( &aConsParam );
     146             :     }
     147           0 :     GetScImport().UnlockSolarMutex();
     148           0 : }
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10