LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - TblStylePrHandler.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 84 87 96.6 %
Date: 2014-04-11 Functions: 11 11 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             :  * 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             : #include <TblStylePrHandler.hxx>
      21             : #include <PropertyMap.hxx>
      22             : #include <ooxml/resourceids.hxx>
      23             : #include <dmapperLoggers.hxx>
      24             : #include <resourcemodel/QNameToString.hxx>
      25             : 
      26             : #include "dmapperLoggers.hxx"
      27             : 
      28             : namespace writerfilter {
      29             : namespace dmapper {
      30             : 
      31        2567 : TblStylePrHandler::TblStylePrHandler( DomainMapper & rDMapper ) :
      32             : LoggedProperties(dmapper_logger, "TblStylePrHandler"),
      33             : m_rDMapper( rDMapper ),
      34        2567 : m_pTablePropsHandler( new TablePropertiesHandler( true ) ),
      35             : m_nType( TBL_STYLE_UNKNOWN ),
      36        5134 : m_pProperties( new PropertyMap )
      37             : {
      38        2567 : }
      39             : 
      40        7701 : TblStylePrHandler::~TblStylePrHandler( )
      41             : {
      42        2567 :     delete m_pTablePropsHandler, m_pTablePropsHandler = NULL;
      43        5134 : }
      44             : 
      45         909 : OUString TblStylePrHandler::getTypeString()
      46             : {
      47         909 :     switch (m_nType)
      48             :     {
      49           0 :         case TBL_STYLE_WHOLETABLE: return OUString("wholeTable");
      50         209 :         case TBL_STYLE_FIRSTROW: return OUString("firstRow");
      51         131 :         case TBL_STYLE_LASTROW: return OUString("lastRow");
      52         125 :         case TBL_STYLE_FIRSTCOL: return OUString("firstCol");
      53         113 :         case TBL_STYLE_LASTCOL: return OUString("lastCol");
      54          63 :         case TBL_STYLE_BAND1VERT: return OUString("band1Vert");
      55          22 :         case TBL_STYLE_BAND2VERT: return OUString("band2Vert");
      56          75 :         case TBL_STYLE_BAND1HORZ: return OUString("band1Horz");
      57          29 :         case TBL_STYLE_BAND2HORZ: return OUString("band2Horz");
      58          36 :         case TBL_STYLE_NECELL: return OUString("neCell");
      59          43 :         case TBL_STYLE_NWCELL: return OUString("nwCell");
      60           7 :         case TBL_STYLE_SECELL: return OUString("seCell");
      61          56 :         case TBL_STYLE_SWCELL: return OUString("swCell");
      62           0 :         default: break;
      63             :     }
      64           0 :     return OUString();
      65             : }
      66             : 
      67        1380 : void TblStylePrHandler::lcl_attribute(Id rName, Value & rVal)
      68             : {
      69             : #ifdef DEBUG_DOMAINMAPPER
      70             :     dmapper_logger->startElement("TblStylePrHandler.attribute");
      71             :     dmapper_logger->attribute("name", (*QNameToString::Instance())(rName));
      72             :     dmapper_logger->chars(rVal.toString());
      73             :     dmapper_logger->endElement();
      74             : #endif
      75             : 
      76        1380 :     switch ( rName )
      77             :     {
      78             :         case NS_ooxml::LN_CT_TblStyleOverrideType:
      79             :             {
      80             :                 // The tokenid should be the same in the model.xml than
      81             :                 // in the TblStyleType enum
      82         909 :                 m_nType = TblStyleType( rVal.getInt( ) );
      83             :             }
      84         909 :             break;
      85             :     }
      86        1380 : }
      87             : 
      88        7987 : void TblStylePrHandler::lcl_sprm(Sprm & rSprm)
      89             : {
      90             : #ifdef DEBUG_DOMAINMAPPER
      91             :     dmapper_logger->startElement("TblStylePrHandler.sprm");
      92             :     dmapper_logger->attribute("sprm", rSprm.toString());
      93             : #endif
      94             : 
      95        7987 :     Value::Pointer_t pValue = rSprm.getValue();
      96        7987 :     switch ( rSprm.getId( ) )
      97             :     {
      98             :         case NS_ooxml::LN_CT_PPrBase:
      99             :         case NS_ooxml::LN_EG_RPrBase:
     100             :         case NS_ooxml::LN_CT_TblPrBase:
     101             :         case NS_ooxml::LN_CT_TrPrBase:
     102             :         case NS_ooxml::LN_CT_TcPrBase:
     103             :         {
     104        2330 :             std::vector<beans::PropertyValue> aSavedGrabBag;
     105        4568 :             bool bGrabBag = rSprm.getId() == NS_ooxml::LN_CT_PPrBase ||
     106        3855 :                 rSprm.getId() == NS_ooxml::LN_EG_RPrBase ||
     107        4745 :                 rSprm.getId() == NS_ooxml::LN_CT_TblPrBase ||
     108        3128 :                 rSprm.getId() == NS_ooxml::LN_CT_TcPrBase;
     109        2330 :             if (bGrabBag)
     110             :             {
     111        2322 :                 aSavedGrabBag = m_aInteropGrabBag;
     112        2322 :                 m_aInteropGrabBag.clear();
     113             :             }
     114        2330 :             resolveSprmProps( rSprm );
     115        2330 :             if (bGrabBag)
     116             :             {
     117        2322 :                 if (rSprm.getId() == NS_ooxml::LN_CT_PPrBase)
     118          92 :                     aSavedGrabBag.push_back(getInteropGrabBag("pPr"));
     119        2230 :                 else if (rSprm.getId() == NS_ooxml::LN_EG_RPrBase)
     120         621 :                     aSavedGrabBag.push_back(getInteropGrabBag("rPr"));
     121        1609 :                 else if (rSprm.getId() == NS_ooxml::LN_CT_TblPrBase)
     122         819 :                     aSavedGrabBag.push_back(getInteropGrabBag("tblPr"));
     123         790 :                 else if (rSprm.getId() == NS_ooxml::LN_CT_TcPrBase)
     124         790 :                     aSavedGrabBag.push_back(getInteropGrabBag("tcPr"));
     125        2322 :                 m_aInteropGrabBag = aSavedGrabBag;
     126        2330 :             }
     127             :         }
     128        2330 :             break;
     129             :         default:
     130             :             // Tables specific properties have to handled here
     131        5657 :             m_pTablePropsHandler->SetProperties( m_pProperties );
     132        5657 :             m_pTablePropsHandler->SetInteropGrabBag(m_aInteropGrabBag);
     133        5657 :             bool bRet = m_pTablePropsHandler->sprm( rSprm );
     134             : 
     135        5657 :             if ( !bRet )
     136             :             {
     137             :                 // The DomainMapper can handle some of the properties
     138        1687 :                 m_rDMapper.PushStyleSheetProperties( m_pProperties, true );
     139             :                 // Just pass a non-empty string, the array will have a single element anyway.
     140        1687 :                 m_rDMapper.enableInteropGrabBag("TblStylePrHandler");
     141        1687 :                 m_rDMapper.sprm( rSprm );
     142        1687 :                 uno::Sequence<beans::PropertyValue> aGrabBag = m_rDMapper.getInteropGrabBag().Value.get< uno::Sequence<beans::PropertyValue> >();
     143        1687 :                 if (aGrabBag.hasElements())
     144        1485 :                     m_aInteropGrabBag.push_back(aGrabBag[0]);
     145        1687 :                 m_rDMapper.PopStyleSheetProperties( true );
     146             :             }
     147        7987 :     }
     148             : 
     149             : #ifdef DEBUG_DOMAINMAPPER
     150             :     dmapper_logger->endElement();
     151             : #endif
     152        7987 : }
     153             : 
     154        2330 : void TblStylePrHandler::resolveSprmProps(Sprm & rSprm)
     155             : {
     156        2330 :     writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     157        2330 :     if( pProperties.get())
     158        2330 :         pProperties->resolve(*this);
     159        2330 : }
     160             : 
     161         909 : void TblStylePrHandler::appendInteropGrabBag(const OUString& aKey, const OUString& aValue)
     162             : {
     163         909 :     beans::PropertyValue aProperty;
     164         909 :     aProperty.Name = aKey;
     165         909 :     aProperty.Value = uno::makeAny(aValue);
     166         909 :     m_aInteropGrabBag.push_back(aProperty);
     167         909 : }
     168             : 
     169        4565 : beans::PropertyValue TblStylePrHandler::getInteropGrabBag(const OUString& aName)
     170             : {
     171        4565 :     beans::PropertyValue aRet;
     172        4565 :     aRet.Name = aName;
     173             : 
     174        9130 :     uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
     175        4565 :     beans::PropertyValue* pSeq = aSeq.getArray();
     176       13389 :     for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
     177        8824 :         *pSeq++ = *i;
     178             : 
     179        4565 :     aRet.Value = uno::makeAny(aSeq);
     180        9130 :     return aRet;
     181             : }
     182             : 
     183          42 : }}
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10