LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextHeaderFooterContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 68 79 86.1 %
Date: 2014-11-03 Functions: 5 10 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 <com/sun/star/text/XParagraphAppend.hpp>
      22             : #include <com/sun/star/text/XRelativeTextContentRemove.hpp>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include "XMLTextHeaderFooterContext.hxx"
      26             : #include <xmloff/XMLTextTableContext.hxx>
      27             : #include <xmloff/xmlimp.hxx>
      28             : 
      29             : 
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::xml::sax;
      34             : using namespace ::com::sun::star::text;
      35             : using namespace ::com::sun::star::beans;
      36             : 
      37             : 
      38           0 : TYPEINIT1( XMLTextHeaderFooterContext, SvXMLImportContext );
      39             : 
      40         220 : XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
      41             :                        const OUString& rLName,
      42             :                        const uno::Reference<
      43             :                             xml::sax::XAttributeList > &,
      44             :                         const Reference < XPropertySet > & rPageStylePropSet,
      45             :                        bool bFooter, bool bLft, bool bFrst ) :
      46             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      47             :     xPropSet( rPageStylePropSet ),
      48             :     sOn( bFooter ? OUString("FooterIsOn") : OUString("HeaderIsOn") ),
      49             :     sShareContent( bFooter ? OUString("FooterIsShared") : OUString("HeaderIsShared") ),
      50             :     sShareContentFirst( "FirstIsShared" ),
      51             :     sText( bFooter ? OUString("FooterText") : OUString("HeaderText") ),
      52             :     sTextFirst(bFooter ? OUString("FooterTextFirst") : OUString("HeaderTextFirst")),
      53             :     sTextLeft( bFooter ?  OUString("FooterTextLeft") : OUString("HeaderTextLeft") ),
      54             :     bInsertContent( true ),
      55             :     bLeft( bLft ),
      56         220 :     bFirst( bFrst )
      57             : {
      58             :     // NOTE: if this ever handles XML_DISPLAY attr then beware of fdo#72850 !
      59         220 :     if( bLeft || bFirst )
      60             :     {
      61          58 :         Any aAny;
      62             : 
      63          58 :         aAny = xPropSet->getPropertyValue( sOn );
      64          58 :         bool bOn = *(sal_Bool *)aAny.getValue();
      65             : 
      66          58 :         if( bOn )
      67             :         {
      68          58 :             if (bLeft)
      69             :             {
      70          30 :                 aAny = xPropSet->getPropertyValue( sShareContent );
      71             :                 bool bShared;
      72          30 :                 if (!(aAny >>= bShared))
      73             :                     assert(false); // should return a value!
      74          30 :                 if( bShared )
      75             :                 {
      76             :                     // Don't share headers any longer
      77          30 :                     bShared = false;
      78          30 :                     aAny.setValue( &bShared, ::getBooleanCppuType() );
      79          30 :                     xPropSet->setPropertyValue( sShareContent, aAny );
      80             :                 }
      81             :             }
      82          58 :             if (bFirst)
      83             :             {
      84          28 :                 aAny = xPropSet->getPropertyValue( sShareContentFirst );
      85             :                 bool bSharedFirst;
      86          28 :                 if (!(aAny >>= bSharedFirst))
      87             :                     assert(false); // should return a value!
      88          28 :                 if( bSharedFirst )
      89             :                 {
      90             :                     // Don't share first/right headers any longer
      91          16 :                     bSharedFirst = false;
      92          16 :                     aAny.setValue( &bSharedFirst, ::getBooleanCppuType() );
      93          16 :                     xPropSet->setPropertyValue( sShareContentFirst, aAny );
      94             :                 }
      95             :             }
      96             :         }
      97             :         else
      98             :         {
      99             :             // If headers or footers are switched off, no content must be
     100             :             // inserted.
     101           0 :             bInsertContent = false;
     102          58 :         }
     103             :     }
     104         220 : }
     105             : 
     106         440 : XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
     107             : {
     108         440 : }
     109             : 
     110         262 : SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext(
     111             :     sal_uInt16 nPrefix,
     112             :     const OUString& rLocalName,
     113             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     114             : {
     115         262 :     SvXMLImportContext *pContext = 0;
     116         262 :     if( bInsertContent )
     117             :     {
     118         262 :         if( !xOldTextCursor.is() )
     119             :         {
     120         220 :             bool bRemoveContent = true;
     121         220 :             Any aAny;
     122         220 :             if( bLeft || bFirst )
     123             :             {
     124             :                 // Headers and footers are switched on already,
     125             :                 // and they aren't shared.
     126         116 :                 if (bLeft)
     127          30 :                     aAny = xPropSet->getPropertyValue( sTextLeft );
     128             :                 else
     129          28 :                     aAny = xPropSet->getPropertyValue( sTextFirst );
     130             :             }
     131             :             else
     132             :             {
     133         162 :                 aAny = xPropSet->getPropertyValue( sOn );
     134         162 :                 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
     135             : 
     136         162 :                 if( !bOn )
     137             :                 {
     138             :                     // Switch header on
     139         162 :                     bOn = sal_True;
     140         162 :                     aAny.setValue( &bOn, ::getBooleanCppuType() );
     141         162 :                     xPropSet->setPropertyValue( sOn, aAny );
     142             : 
     143             :                     // The content has not to be removed, because the header
     144             :                     // or footer is empty already.
     145         162 :                     bRemoveContent = false;
     146             :                 }
     147             : 
     148             :                 // If a header or footer is not shared, share it now.
     149         162 :                 aAny = xPropSet->getPropertyValue( sShareContent );
     150         162 :                 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
     151         162 :                 if( !bShared )
     152             :                 {
     153           0 :                     bShared = sal_True;
     154           0 :                     aAny.setValue( &bShared, ::getBooleanCppuType() );
     155           0 :                     xPropSet->setPropertyValue( sShareContent, aAny );
     156             :                 }
     157             : 
     158         162 :                 aAny = xPropSet->getPropertyValue( sText );
     159             :             }
     160             : 
     161         440 :             Reference < XText > xText;
     162         220 :             aAny >>= xText;
     163             : 
     164         220 :             if( bRemoveContent )
     165             :             {
     166          58 :                 xText->setString(OUString());
     167             :                 // fdo#82165 shapes anchored at the beginning or end survive
     168             :                 // setString("") - kill them the hard way: SwDoc::DelFullPara()
     169             :                 uno::Reference<text::XParagraphAppend> const xAppend(
     170          58 :                         xText, uno::UNO_QUERY_THROW);
     171             :                 uno::Reference<lang::XComponent> const xPara(
     172          58 :                     xAppend->finishParagraph(
     173          58 :                         uno::Sequence<beans::PropertyValue>()),
     174         116 :                     uno::UNO_QUERY_THROW);
     175         116 :                 xPara->dispose();
     176             :             }
     177             : 
     178             :             rtl::Reference < XMLTextImportHelper > xTxtImport =
     179         440 :                 GetImport().GetTextImport();
     180             : 
     181         220 :             xOldTextCursor = xTxtImport->GetCursor();
     182         440 :             xTxtImport->SetCursor( xText->createTextCursor() );
     183             :         }
     184             : 
     185             :         pContext =
     186         262 :             GetImport().GetTextImport()->CreateTextChildContext(
     187         262 :                 GetImport(), nPrefix, rLocalName, xAttrList,
     188         524 :                 XML_TEXT_TYPE_HEADER_FOOTER );
     189             :     }
     190         262 :     if( !pContext )
     191           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     192             : 
     193         262 :     return pContext;
     194             : }
     195             : 
     196         220 : void XMLTextHeaderFooterContext::EndElement()
     197             : {
     198         220 :     if( xOldTextCursor.is() )
     199             :     {
     200         220 :         GetImport().GetTextImport()->DeleteParagraph();
     201         220 :         GetImport().GetTextImport()->SetCursor( xOldTextCursor );
     202             :     }
     203           0 :     else if( !bLeft )
     204             :     {
     205             :         // If no content has been inserted inro the header or footer,
     206             :         // switch it off.
     207           0 :         sal_Bool bOn = sal_False;
     208           0 :         Any aAny;
     209           0 :         aAny.setValue( &bOn, ::getBooleanCppuType() );
     210           0 :         xPropSet->setPropertyValue( sOn, aAny );
     211             :     }
     212         220 : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10