LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextHeaderFooterContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 68 79 86.1 %
Date: 2015-06-13 12:38:46 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         160 : 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         160 :     bFirst( bFrst )
      57             : {
      58             :     // NOTE: if this ever handles XML_DISPLAY attr then beware of fdo#72850 !
      59         160 :     if( bLeft || bFirst )
      60             :     {
      61          41 :         Any aAny;
      62             : 
      63          41 :         aAny = xPropSet->getPropertyValue( sOn );
      64          41 :         bool bOn = *static_cast<sal_Bool const *>(aAny.getValue());
      65             : 
      66          41 :         if( bOn )
      67             :         {
      68          41 :             if (bLeft)
      69             :             {
      70          27 :                 aAny = xPropSet->getPropertyValue( sShareContent );
      71             :                 bool bShared;
      72          27 :                 if (!(aAny >>= bShared))
      73             :                     assert(false); // should return a value!
      74          27 :                 if( bShared )
      75             :                 {
      76             :                     // Don't share headers any longer
      77          27 :                     bShared = false;
      78          27 :                     aAny.setValue( &bShared, cppu::UnoType<bool>::get() );
      79          27 :                     xPropSet->setPropertyValue( sShareContent, aAny );
      80             :                 }
      81             :             }
      82          41 :             if (bFirst)
      83             :             {
      84          14 :                 aAny = xPropSet->getPropertyValue( sShareContentFirst );
      85             :                 bool bSharedFirst;
      86          14 :                 if (!(aAny >>= bSharedFirst))
      87             :                     assert(false); // should return a value!
      88          14 :                 if( bSharedFirst )
      89             :                 {
      90             :                     // Don't share first/right headers any longer
      91           8 :                     bSharedFirst = false;
      92           8 :                     aAny.setValue( &bSharedFirst, cppu::UnoType<bool>::get() );
      93           8 :                     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          41 :         }
     103             :     }
     104         160 : }
     105             : 
     106         320 : XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
     107             : {
     108         320 : }
     109             : 
     110         181 : SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext(
     111             :     sal_uInt16 nPrefix,
     112             :     const OUString& rLocalName,
     113             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     114             : {
     115         181 :     SvXMLImportContext *pContext = 0;
     116         181 :     if( bInsertContent )
     117             :     {
     118         181 :         if( !xOldTextCursor.is() )
     119             :         {
     120         160 :             bool bRemoveContent = true;
     121         160 :             Any aAny;
     122         160 :             if( bLeft || bFirst )
     123             :             {
     124             :                 // Headers and footers are switched on already,
     125             :                 // and they aren't shared.
     126          82 :                 if (bLeft)
     127          27 :                     aAny = xPropSet->getPropertyValue( sTextLeft );
     128             :                 else
     129          14 :                     aAny = xPropSet->getPropertyValue( sTextFirst );
     130             :             }
     131             :             else
     132             :             {
     133         119 :                 aAny = xPropSet->getPropertyValue( sOn );
     134         119 :                 sal_Bool bOn = *static_cast<sal_Bool const *>(aAny.getValue());
     135             : 
     136         119 :                 if( !bOn )
     137             :                 {
     138             :                     // Switch header on
     139         119 :                     bOn = sal_True;
     140         119 :                     aAny.setValue( &bOn, cppu::UnoType<bool>::get() );
     141         119 :                     xPropSet->setPropertyValue( sOn, aAny );
     142             : 
     143             :                     // The content has not to be removed, because the header
     144             :                     // or footer is empty already.
     145         119 :                     bRemoveContent = false;
     146             :                 }
     147             : 
     148             :                 // If a header or footer is not shared, share it now.
     149         119 :                 aAny = xPropSet->getPropertyValue( sShareContent );
     150         119 :                 sal_Bool bShared = *static_cast<sal_Bool const *>(aAny.getValue());
     151         119 :                 if( !bShared )
     152             :                 {
     153           0 :                     bShared = sal_True;
     154           0 :                     aAny.setValue( &bShared, cppu::UnoType<bool>::get() );
     155           0 :                     xPropSet->setPropertyValue( sShareContent, aAny );
     156             :                 }
     157             : 
     158         119 :                 aAny = xPropSet->getPropertyValue( sText );
     159             :             }
     160             : 
     161         320 :             Reference < XText > xText;
     162         160 :             aAny >>= xText;
     163             : 
     164         160 :             if( bRemoveContent )
     165             :             {
     166          41 :                 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          41 :                         xText, uno::UNO_QUERY_THROW);
     171             :                 uno::Reference<lang::XComponent> const xPara(
     172          41 :                     xAppend->finishParagraph(
     173          41 :                         uno::Sequence<beans::PropertyValue>()),
     174          82 :                     uno::UNO_QUERY_THROW);
     175          82 :                 xPara->dispose();
     176             :             }
     177             : 
     178             :             rtl::Reference < XMLTextImportHelper > xTxtImport =
     179         320 :                 GetImport().GetTextImport();
     180             : 
     181         160 :             xOldTextCursor = xTxtImport->GetCursor();
     182         320 :             xTxtImport->SetCursor( xText->createTextCursor() );
     183             :         }
     184             : 
     185             :         pContext =
     186         181 :             GetImport().GetTextImport()->CreateTextChildContext(
     187         181 :                 GetImport(), nPrefix, rLocalName, xAttrList,
     188         362 :                 XML_TEXT_TYPE_HEADER_FOOTER );
     189             :     }
     190         181 :     if( !pContext )
     191           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     192             : 
     193         181 :     return pContext;
     194             : }
     195             : 
     196         160 : void XMLTextHeaderFooterContext::EndElement()
     197             : {
     198         160 :     if( xOldTextCursor.is() )
     199             :     {
     200         160 :         GetImport().GetTextImport()->DeleteParagraph();
     201         160 :         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, cppu::UnoType<bool>::get() );
     210           0 :         xPropSet->setPropertyValue( sOn, aAny );
     211             :     }
     212         160 : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11