LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextHeaderFooterContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 75 53.3 %
Date: 2012-08-25 Functions: 5 10 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 60 172 34.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/text/XText.hpp>
      30                 :            : #include <com/sun/star/text/XRelativeTextContentRemove.hpp>
      31                 :            : #include <xmloff/nmspmap.hxx>
      32                 :            : #include "xmloff/xmlnmspe.hxx"
      33                 :            : #include "XMLTextHeaderFooterContext.hxx"
      34                 :            : #include <xmloff/XMLTextTableContext.hxx>
      35                 :            : #include <xmloff/xmlimp.hxx>
      36                 :            : 
      37                 :            : 
      38                 :            : using ::rtl::OUString;
      39                 :            : using ::rtl::OUStringBuffer;
      40                 :            : 
      41                 :            : using namespace ::com::sun::star;
      42                 :            : using namespace ::com::sun::star::uno;
      43                 :            : using namespace ::com::sun::star::xml::sax;
      44                 :            : using namespace ::com::sun::star::text;
      45                 :            : using namespace ::com::sun::star::beans;
      46                 :            : 
      47                 :            : 
      48 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLTextHeaderFooterContext, SvXMLImportContext );
      49                 :            : 
      50                 :         20 : XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
      51                 :            :                        const OUString& rLName,
      52                 :            :                        const uno::Reference<
      53                 :            :                             xml::sax::XAttributeList > &,
      54                 :            :                         const Reference < XPropertySet > & rPageStylePropSet,
      55                 :            :                        sal_Bool bFooter, sal_Bool bLft, sal_Bool bFrst ) :
      56                 :            :     SvXMLImportContext( rImport, nPrfx, rLName ),
      57                 :            :     xPropSet( rPageStylePropSet ),
      58                 :            :     sOn( bFooter ? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" )) : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" )) ),
      59                 :            :     sShareContent( bFooter ? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsShared" ))
      60                 :            :                                                       : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsShared" )) ),
      61                 :            :     sShareContentFirst( "FirstIsShared" ),
      62                 :            :     sText( bFooter ? OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterText" )) : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderText" )) ),
      63                 :            :     sTextFirst(bFooter ? OUString("FooterTextFirst") : OUString("HeaderTextFirst")),
      64                 :            :     sTextLeft( bFooter ?  OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterTextLeft" ))
      65                 :            :                                                      : OUString(RTL_CONSTASCII_USTRINGPARAM( "HeaderTextLeft" )) ),
      66                 :            :     bInsertContent( sal_True ),
      67                 :            :     bLeft( bLft ),
      68 [ +  + ][ +  - ]:         20 :     bFirst( bFrst )
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
         [ +  - ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  - ]
                 [ +  - ]
      69                 :            : {
      70 [ +  - ][ -  + ]:         20 :     if( bLeft || bFirst )
      71                 :            :     {
      72                 :          0 :         Any aAny;
      73                 :            : 
      74 [ #  # ][ #  # ]:          0 :         aAny = xPropSet->getPropertyValue( sOn );
      75                 :          0 :         sal_Bool bOn = *(sal_Bool *)aAny.getValue();
      76                 :            : 
      77         [ #  # ]:          0 :         if( bOn )
      78                 :            :         {
      79         [ #  # ]:          0 :             if (bLeft)
      80                 :            :             {
      81 [ #  # ][ #  # ]:          0 :                 aAny = xPropSet->getPropertyValue( sShareContent );
      82                 :          0 :                 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
      83         [ #  # ]:          0 :                 if( bShared )
      84                 :            :                 {
      85                 :            :                     // Don't share headers any longer
      86                 :          0 :                     bShared = sal_False;
      87         [ #  # ]:          0 :                     aAny.setValue( &bShared, ::getBooleanCppuType() );
      88 [ #  # ][ #  # ]:          0 :                     xPropSet->setPropertyValue( sShareContent, aAny );
      89                 :            :                 }
      90                 :            :             }
      91         [ #  # ]:          0 :             if (bFirst)
      92                 :            :             {
      93 [ #  # ][ #  # ]:          0 :                 aAny = xPropSet->getPropertyValue( sShareContentFirst );
      94                 :          0 :                 sal_Bool bSharedFirst = *(sal_Bool *)aAny.getValue();
      95         [ #  # ]:          0 :                 if( bSharedFirst )
      96                 :            :                 {
      97                 :            :                     // Don't share first/right headers any longer
      98                 :          0 :                     bSharedFirst = sal_False;
      99         [ #  # ]:          0 :                     aAny.setValue( &bSharedFirst, ::getBooleanCppuType() );
     100 [ #  # ][ #  # ]:          0 :                     xPropSet->setPropertyValue( sShareContentFirst, aAny );
     101                 :            :                 }
     102                 :            :             }
     103                 :            :         }
     104                 :            :         else
     105                 :            :         {
     106                 :            :             // If headers or footers are switched off, no content must be
     107                 :            :             // inserted.
     108                 :          0 :             bInsertContent = sal_False;
     109                 :          0 :         }
     110                 :            :     }
     111                 :         20 : }
     112                 :            : 
     113                 :         20 : XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
     114                 :            : {
     115         [ -  + ]:         40 : }
     116                 :            : 
     117                 :         24 : SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext(
     118                 :            :     sal_uInt16 nPrefix,
     119                 :            :     const OUString& rLocalName,
     120                 :            :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     121                 :            : {
     122                 :         24 :     SvXMLImportContext *pContext = 0;
     123         [ +  - ]:         24 :     if( bInsertContent )
     124                 :            :     {
     125         [ +  + ]:         24 :         if( !xOldTextCursor.is() )
     126                 :            :         {
     127                 :         20 :             sal_Bool bRemoveContent = sal_True;
     128                 :         20 :             Any aAny;
     129 [ -  + ][ +  - ]:         20 :             if( bLeft || bFirst )
     130                 :            :             {
     131                 :            :                 // Headers and footers are switched on already,
     132                 :            :                 // and they aren't shared.
     133         [ #  # ]:          0 :                 if (bLeft)
     134 [ #  # ][ #  # ]:          0 :                     aAny = xPropSet->getPropertyValue( sTextLeft );
     135                 :            :                 else
     136 [ #  # ][ #  # ]:          0 :                     aAny = xPropSet->getPropertyValue( sTextFirst );
     137                 :            :             }
     138                 :            :             else
     139                 :            :             {
     140 [ +  - ][ +  - ]:         20 :                 aAny = xPropSet->getPropertyValue( sOn );
     141                 :         20 :                 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
     142                 :            : 
     143         [ +  - ]:         20 :                 if( !bOn )
     144                 :            :                 {
     145                 :            :                     // Switch header on
     146                 :         20 :                     bOn = sal_True;
     147         [ +  - ]:         20 :                     aAny.setValue( &bOn, ::getBooleanCppuType() );
     148 [ +  - ][ +  - ]:         20 :                     xPropSet->setPropertyValue( sOn, aAny );
     149                 :            : 
     150                 :            :                     // The content has not to be removed, because the header
     151                 :            :                     // or footer is empty already.
     152                 :         20 :                     bRemoveContent = sal_False;
     153                 :            :                 }
     154                 :            : 
     155                 :            :                 // If a header or footer is not shared, share it now.
     156 [ +  - ][ +  - ]:         20 :                 aAny = xPropSet->getPropertyValue( sShareContent );
     157                 :         20 :                 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
     158         [ -  + ]:         20 :                 if( !bShared )
     159                 :            :                 {
     160                 :          0 :                     bShared = sal_True;
     161         [ #  # ]:          0 :                     aAny.setValue( &bShared, ::getBooleanCppuType() );
     162 [ #  # ][ #  # ]:          0 :                     xPropSet->setPropertyValue( sShareContent, aAny );
     163                 :            :                 }
     164                 :            : 
     165 [ +  - ][ +  - ]:         20 :                 aAny = xPropSet->getPropertyValue( sText );
     166                 :            :             }
     167                 :            : 
     168                 :         20 :             Reference < XText > xText;
     169         [ +  - ]:         20 :             aAny >>= xText;
     170                 :            : 
     171         [ -  + ]:         20 :             if( bRemoveContent )
     172                 :            :             {
     173                 :          0 :                 OUString aText;
     174 [ #  # ][ #  # ]:          0 :                 xText->setString( aText );
     175                 :            :             }
     176                 :            : 
     177                 :            :             UniReference < XMLTextImportHelper > xTxtImport =
     178         [ +  - ]:         20 :                 GetImport().GetTextImport();
     179                 :            : 
     180 [ +  - ][ +  - ]:         20 :             xOldTextCursor = xTxtImport->GetCursor();
                 [ +  - ]
     181 [ +  - ][ +  - ]:         20 :             xTxtImport->SetCursor( xText->createTextCursor() );
         [ +  - ][ +  - ]
                 [ +  - ]
     182                 :            :         }
     183                 :            : 
     184                 :            :         pContext =
     185                 :         24 :             GetImport().GetTextImport()->CreateTextChildContext(
     186                 :         24 :                 GetImport(), nPrefix, rLocalName, xAttrList,
     187 [ +  - ][ +  - ]:         24 :                 XML_TEXT_TYPE_HEADER_FOOTER );
     188                 :            :     }
     189         [ -  + ]:         24 :     if( !pContext )
     190         [ #  # ]:          0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     191                 :            : 
     192                 :         24 :     return pContext;
     193                 :            : }
     194                 :            : 
     195                 :         20 : void XMLTextHeaderFooterContext::EndElement()
     196                 :            : {
     197         [ +  - ]:         20 :     if( xOldTextCursor.is() )
     198                 :            :     {
     199 [ +  - ][ +  - ]:         20 :         GetImport().GetTextImport()->DeleteParagraph();
     200 [ +  - ][ +  - ]:         20 :         GetImport().GetTextImport()->SetCursor( xOldTextCursor );
     201                 :            :     }
     202         [ #  # ]:          0 :     else if( !bLeft )
     203                 :            :     {
     204                 :            :         // If no content has been inserted inro the header or footer,
     205                 :            :         // switch it off.
     206                 :          0 :         sal_Bool bOn = sal_False;
     207                 :          0 :         Any aAny;
     208         [ #  # ]:          0 :         aAny.setValue( &bOn, ::getBooleanCppuType() );
     209 [ #  # ][ #  # ]:          0 :         xPropSet->setPropertyValue( sOn, aAny );
     210                 :            :     }
     211                 :         20 : }
     212                 :            : 
     213                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10