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

Generated by: LCOV version 1.10