LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLTableHeaderFooterContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 101 110 91.8 %
Date: 2014-11-03 Functions: 10 20 50.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 <com/sun/star/text/XText.hpp>
      21             : #include <xmloff/nmspmap.hxx>
      22             : #include <xmloff/xmlnmspe.hxx>
      23             : #include "XMLTableHeaderFooterContext.hxx"
      24             : #include <xmloff/xmltoken.hxx>
      25             : #include <comphelper/extract.hxx>
      26             : 
      27             : #include "unonames.hxx"
      28             : 
      29             : using namespace ::com::sun::star;
      30             : using namespace ::com::sun::star::uno;
      31             : using namespace ::com::sun::star::xml::sax;
      32             : using namespace ::com::sun::star::text;
      33             : using namespace ::com::sun::star::beans;
      34             : using namespace xmloff::token;
      35             : 
      36           0 : TYPEINIT1( XMLTableHeaderFooterContext, SvXMLImportContext );
      37             : 
      38        2244 : XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
      39             :                        const OUString& rLName,
      40             :                        const uno::Reference<
      41             :                             xml::sax::XAttributeList > & xAttrList,
      42             :                        const Reference < XPropertySet > & rPageStylePropSet,
      43             :                        bool bFooter, bool bLft ) :
      44             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      45             :     xPropSet( rPageStylePropSet ),
      46             :     sOn( bFooter ? OUString(SC_UNO_PAGE_FTRON) : OUString(SC_UNO_PAGE_HDRON) ),
      47             :     sShareContent( bFooter ? OUString(SC_UNO_PAGE_FTRSHARED) : OUString(SC_UNO_PAGE_HDRSHARED) ),
      48             :     sContent( bFooter ? OUString(SC_UNO_PAGE_RIGHTFTRCON) : OUString(SC_UNO_PAGE_RIGHTHDRCON) ),
      49             :     sContentLeft( bFooter ? OUString(SC_UNO_PAGE_LEFTFTRCONT) : OUString(SC_UNO_PAGE_LEFTHDRCONT) ),
      50             :     bDisplay( true ),
      51             :     bLeft( bLft ),
      52             :     bContainsLeft(false),
      53             :     bContainsRight(false),
      54        2244 :     bContainsCenter(false)
      55             : {
      56        2244 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      57        3370 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      58             :     {
      59        1126 :         const OUString& rAttrName(xAttrList->getNameByIndex( i ));
      60        2252 :         OUString aLName;
      61        1126 :         sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
      62        2252 :         const OUString& rValue(xAttrList->getValueByIndex( i ));
      63             : 
      64             :         // TODO: use a map here
      65        1126 :         if( XML_NAMESPACE_STYLE == nPrefix )
      66             :         {
      67        1126 :             if( IsXMLToken(aLName, XML_DISPLAY ) )
      68        1126 :                 bDisplay = IsXMLToken(rValue, XML_TRUE);
      69             :         }
      70        1126 :     }
      71        2244 :     if( bLeft )
      72             :     {
      73        1092 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      74             : 
      75        1092 :         if( bOn && bDisplay )
      76             :         {
      77           0 :             if( ::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
      78             :                 // Don't share headers any longer
      79           0 :                 xPropSet->setPropertyValue( sShareContent, uno::makeAny(false) );
      80             :         }
      81             :         else
      82             :         {
      83        1092 :             if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
      84             :                 // share headers
      85           0 :                 xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_True) );
      86             :         }
      87             :     }
      88             :     else
      89             :     {
      90        1152 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      91        1152 :         if ( bOn != bDisplay )
      92          34 :             xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
      93             :     }
      94        2244 :     if (bLeft)
      95        1092 :         sCont = sContentLeft;
      96             :     else
      97        1152 :         sCont = sContent;
      98        2244 :     xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
      99        2244 : }
     100             : 
     101        4488 : XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
     102             : {
     103        4488 : }
     104             : 
     105        1466 : SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
     106             :     sal_uInt16 nPrefix,
     107             :     const OUString& rLocalName,
     108             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     109             : {
     110        1466 :     SvXMLImportContext *pContext(0);
     111             : 
     112        2328 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     113         862 :         IsXMLToken(rLocalName, XML_P))
     114             :     {
     115         862 :         if (!xTextCursor.is())
     116             :         {
     117         862 :             if( xHeaderFooterContent.is() )
     118             :             {
     119         862 :                 uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
     120         862 :                 xText->setString(sEmpty);
     121         862 :                 xTextCursor.set(xText->createTextCursor());
     122         862 :                 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     123         862 :                 GetImport().GetTextImport()->SetCursor( xTextCursor );
     124         862 :                 bContainsCenter = true;
     125             :             }
     126             :         }
     127             :         pContext =
     128         862 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     129             :                                                                     nPrefix,
     130             :                                                                     rLocalName,
     131        1724 :                                                                     xAttrList);
     132             :     }
     133             :     else
     134             :     {
     135         604 :         if (nPrefix == XML_NAMESPACE_STYLE)
     136             :         {
     137         604 :             if (xHeaderFooterContent.is())
     138             :             {
     139         604 :                 uno::Reference < text::XText > xText;
     140         604 :                 if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
     141             :                 {
     142         290 :                     xText.set(xHeaderFooterContent->getLeftText());
     143         290 :                     bContainsLeft = true;
     144             :                 }
     145         314 :                 else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
     146             :                 {
     147          24 :                     xText.set(xHeaderFooterContent->getCenterText());
     148          24 :                     bContainsCenter = true;
     149             :                 }
     150         290 :                 else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
     151             :                 {
     152         290 :                     xText.set(xHeaderFooterContent->getRightText());
     153         290 :                     bContainsRight = true;
     154             :                 }
     155         604 :                 if (xText.is())
     156             :                 {
     157         604 :                     xText->setString(sEmpty);
     158             :                     //SvXMLImport aSvXMLImport( GetImport() );
     159         604 :                     uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
     160         604 :                     pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xAttrList, xTempTextCursor);
     161         604 :                 }
     162             :             }
     163             :         }
     164             :     }
     165        1466 :     if( !pContext )
     166           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     167             : 
     168        1466 :     return pContext;
     169             : }
     170             : 
     171        2244 : void XMLTableHeaderFooterContext::EndElement()
     172             : {
     173        2244 :     if( GetImport().GetTextImport()->GetCursor().is() )
     174             :     {
     175             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     176         862 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     177             :         {
     178        1724 :             GetImport().GetTextImport()->GetText()->insertString(
     179        1724 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     180        1724 :                 true );
     181             :         }
     182         862 :         GetImport().GetTextImport()->ResetCursor();
     183             :     }
     184        2244 :     if (xOldTextCursor.is())
     185           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     186        2244 :     if (xHeaderFooterContent.is())
     187             :     {
     188        2244 :         if (!bContainsLeft)
     189        1954 :             xHeaderFooterContent->getLeftText()->setString(sEmpty);
     190        2244 :         if (!bContainsCenter)
     191        1358 :             xHeaderFooterContent->getCenterText()->setString(sEmpty);
     192        2244 :         if (!bContainsRight)
     193        1954 :             xHeaderFooterContent->getRightText()->setString(sEmpty);
     194             : 
     195        2244 :         xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
     196             :     }
     197        2244 : }
     198             : 
     199           0 : TYPEINIT1( XMLHeaderFooterRegionContext, SvXMLImportContext );
     200             : 
     201         604 : XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
     202             :                        const OUString& rLName,
     203             :                        const uno::Reference<
     204             :                             xml::sax::XAttributeList > & /* xAttrList */,
     205             :                        uno::Reference< text::XTextCursor >& xCursor ) :
     206             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     207         604 :     xTextCursor ( xCursor )
     208             : {
     209         604 :     xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     210         604 :     GetImport().GetTextImport()->SetCursor( xTextCursor );
     211         604 : }
     212             : 
     213        1208 : XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
     214             : {
     215        1208 : }
     216             : 
     217         620 : SvXMLImportContext *XMLHeaderFooterRegionContext::CreateChildContext(
     218             :     sal_uInt16 nPrefix,
     219             :     const OUString& rLocalName,
     220             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     221             : {
     222         620 :     SvXMLImportContext *pContext(0);
     223             : 
     224        1240 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     225         620 :         IsXMLToken(rLocalName, XML_P))
     226             :     {
     227             :         pContext =
     228         620 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     229             :                                                                     nPrefix,
     230             :                                                                     rLocalName,
     231        1240 :                                                                     xAttrList);
     232             :     }
     233         620 :     if( !pContext )
     234           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     235             : 
     236         620 :     return pContext;
     237             : }
     238             : 
     239         604 : void XMLHeaderFooterRegionContext::EndElement()
     240             : {
     241         604 :     if( GetImport().GetTextImport()->GetCursor().is() )
     242             :     {
     243             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     244         604 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     245             :         {
     246         604 :             OUString sEmpty;
     247        1208 :             GetImport().GetTextImport()->GetText()->insertString(
     248        1208 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     249        1812 :                 true );
     250             :         }
     251         604 :         GetImport().GetTextImport()->ResetCursor();
     252             :     }
     253         604 :     if (xOldTextCursor.is())
     254           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     255         604 : }
     256             : 
     257             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10