LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLTableHeaderFooterContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 101 110 91.8 %
Date: 2015-06-13 12:38:46 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        1410 : 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        1410 :     bContainsCenter(false)
      55             : {
      56        1410 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      57        2121 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      58             :     {
      59         711 :         const OUString& rAttrName(xAttrList->getNameByIndex( i ));
      60        1422 :         OUString aLName;
      61         711 :         sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
      62        1422 :         const OUString& rValue(xAttrList->getValueByIndex( i ));
      63             : 
      64             :         // TODO: use a map here
      65         711 :         if( XML_NAMESPACE_STYLE == nPrefix )
      66             :         {
      67         711 :             if( IsXMLToken(aLName, XML_DISPLAY ) )
      68         711 :                 bDisplay = IsXMLToken(rValue, XML_TRUE);
      69             :         }
      70         711 :     }
      71        1410 :     if( bLeft )
      72             :     {
      73         690 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      74             : 
      75         690 :         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         690 :             if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
      84             :                 // share headers
      85           0 :                 xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_True) );
      86             :         }
      87             :     }
      88             :     else
      89             :     {
      90         720 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      91         720 :         if ( bOn != bDisplay )
      92          21 :             xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
      93             :     }
      94        1410 :     if (bLeft)
      95         690 :         sCont = sContentLeft;
      96             :     else
      97         720 :         sCont = sContent;
      98        1410 :     xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
      99        1410 : }
     100             : 
     101        2820 : XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
     102             : {
     103        2820 : }
     104             : 
     105         908 : SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
     106             :     sal_uInt16 nPrefix,
     107             :     const OUString& rLocalName,
     108             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     109             : {
     110         908 :     SvXMLImportContext *pContext(0);
     111             : 
     112        1444 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     113         536 :         IsXMLToken(rLocalName, XML_P))
     114             :     {
     115         536 :         if (!xTextCursor.is())
     116             :         {
     117         536 :             if( xHeaderFooterContent.is() )
     118             :             {
     119         536 :                 uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
     120         536 :                 xText->setString(sEmpty);
     121         536 :                 xTextCursor.set(xText->createTextCursor());
     122         536 :                 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     123         536 :                 GetImport().GetTextImport()->SetCursor( xTextCursor );
     124         536 :                 bContainsCenter = true;
     125             :             }
     126             :         }
     127             :         pContext =
     128         536 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     129             :                                                                     nPrefix,
     130             :                                                                     rLocalName,
     131        1072 :                                                                     xAttrList);
     132             :     }
     133             :     else
     134             :     {
     135         372 :         if (nPrefix == XML_NAMESPACE_STYLE)
     136             :         {
     137         372 :             if (xHeaderFooterContent.is())
     138             :             {
     139         372 :                 uno::Reference < text::XText > xText;
     140         372 :                 if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
     141             :                 {
     142         180 :                     xText.set(xHeaderFooterContent->getLeftText());
     143         180 :                     bContainsLeft = true;
     144             :                 }
     145         192 :                 else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
     146             :                 {
     147          12 :                     xText.set(xHeaderFooterContent->getCenterText());
     148          12 :                     bContainsCenter = true;
     149             :                 }
     150         180 :                 else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
     151             :                 {
     152         180 :                     xText.set(xHeaderFooterContent->getRightText());
     153         180 :                     bContainsRight = true;
     154             :                 }
     155         372 :                 if (xText.is())
     156             :                 {
     157         372 :                     xText->setString(sEmpty);
     158             :                     //SvXMLImport aSvXMLImport( GetImport() );
     159         372 :                     uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
     160         372 :                     pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xAttrList, xTempTextCursor);
     161         372 :                 }
     162             :             }
     163             :         }
     164             :     }
     165         908 :     if( !pContext )
     166           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     167             : 
     168         908 :     return pContext;
     169             : }
     170             : 
     171        1410 : void XMLTableHeaderFooterContext::EndElement()
     172             : {
     173        1410 :     if( GetImport().GetTextImport()->GetCursor().is() )
     174             :     {
     175             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     176         536 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     177             :         {
     178        1072 :             GetImport().GetTextImport()->GetText()->insertString(
     179        1072 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     180        1072 :                 true );
     181             :         }
     182         536 :         GetImport().GetTextImport()->ResetCursor();
     183             :     }
     184        1410 :     if (xOldTextCursor.is())
     185           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     186        1410 :     if (xHeaderFooterContent.is())
     187             :     {
     188        1410 :         if (!bContainsLeft)
     189        1230 :             xHeaderFooterContent->getLeftText()->setString(sEmpty);
     190        1410 :         if (!bContainsCenter)
     191         862 :             xHeaderFooterContent->getCenterText()->setString(sEmpty);
     192        1410 :         if (!bContainsRight)
     193        1230 :             xHeaderFooterContent->getRightText()->setString(sEmpty);
     194             : 
     195        1410 :         xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
     196             :     }
     197        1410 : }
     198             : 
     199           0 : TYPEINIT1( XMLHeaderFooterRegionContext, SvXMLImportContext );
     200             : 
     201         372 : 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         372 :     xTextCursor ( xCursor )
     208             : {
     209         372 :     xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     210         372 :     GetImport().GetTextImport()->SetCursor( xTextCursor );
     211         372 : }
     212             : 
     213         744 : XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
     214             : {
     215         744 : }
     216             : 
     217         380 : SvXMLImportContext *XMLHeaderFooterRegionContext::CreateChildContext(
     218             :     sal_uInt16 nPrefix,
     219             :     const OUString& rLocalName,
     220             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     221             : {
     222         380 :     SvXMLImportContext *pContext(0);
     223             : 
     224         760 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     225         380 :         IsXMLToken(rLocalName, XML_P))
     226             :     {
     227             :         pContext =
     228         380 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     229             :                                                                     nPrefix,
     230             :                                                                     rLocalName,
     231         760 :                                                                     xAttrList);
     232             :     }
     233         380 :     if( !pContext )
     234           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     235             : 
     236         380 :     return pContext;
     237             : }
     238             : 
     239         372 : void XMLHeaderFooterRegionContext::EndElement()
     240             : {
     241         372 :     if( GetImport().GetTextImport()->GetCursor().is() )
     242             :     {
     243             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     244         372 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     245             :         {
     246         372 :             OUString sEmpty;
     247         744 :             GetImport().GetTextImport()->GetText()->insertString(
     248         744 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     249        1116 :                 true );
     250             :         }
     251         372 :         GetImport().GetTextImport()->ResetCursor();
     252             :     }
     253         372 :     if (xOldTextCursor.is())
     254           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     255         372 : }
     256             : 
     257             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11