LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - XMLTableHeaderFooterContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 98 110 89.1 %
Date: 2012-12-27 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 ::rtl::OUString;
      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             : using namespace xmloff::token;
      36             : 
      37             : using rtl::OUString;
      38             : 
      39           0 : TYPEINIT1( XMLTableHeaderFooterContext, SvXMLImportContext );
      40             : 
      41         176 : XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
      42             :                        const OUString& rLName,
      43             :                        const uno::Reference<
      44             :                             xml::sax::XAttributeList > & xAttrList,
      45             :                        const Reference < XPropertySet > & rPageStylePropSet,
      46             :                        bool bFooter, bool bLft ) :
      47             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      48             :     xPropSet( rPageStylePropSet ),
      49             :     sOn( bFooter ? OUString(SC_UNO_PAGE_FTRON) : OUString(SC_UNO_PAGE_HDRON) ),
      50             :     sShareContent( bFooter ? OUString(SC_UNO_PAGE_FTRSHARED) : OUString(SC_UNO_PAGE_HDRSHARED) ),
      51             :     sContent( bFooter ? OUString(SC_UNO_PAGE_RIGHTFTRCON) : OUString(SC_UNO_PAGE_RIGHTHDRCON) ),
      52             :     sContentLeft( bFooter ? OUString(SC_UNO_PAGE_LEFTFTRCONT) : OUString(SC_UNO_PAGE_LEFTHDRCONT) ),
      53             :     bDisplay( true ),
      54             :     bLeft( bLft ),
      55             :     bContainsLeft(false),
      56             :     bContainsRight(false),
      57         176 :     bContainsCenter(false)
      58             : {
      59         176 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      60         264 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      61             :     {
      62          88 :         const OUString& rAttrName(xAttrList->getNameByIndex( i ));
      63          88 :         OUString aLName;
      64          88 :         sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
      65          88 :         const OUString& rValue(xAttrList->getValueByIndex( i ));
      66             : 
      67             :         // TODO: use a map here
      68          88 :         if( XML_NAMESPACE_STYLE == nPrefix )
      69             :         {
      70          88 :             if( IsXMLToken(aLName, XML_DISPLAY ) )
      71          88 :                 bDisplay = IsXMLToken(rValue, XML_TRUE);
      72             :         }
      73          88 :     }
      74         176 :     if( bLeft )
      75             :     {
      76          88 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      77             : 
      78          88 :         if( bOn && bDisplay )
      79             :         {
      80           0 :             if( ::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
      81             :                 // Don't share headers any longer
      82           0 :                 xPropSet->setPropertyValue( sShareContent, uno::makeAny(false) );
      83             :         }
      84             :         else
      85             :         {
      86          88 :             if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
      87             :                 // share headers
      88           0 :                 xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_True) );
      89             :         }
      90             :     }
      91             :     else
      92             :     {
      93          88 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      94          88 :         if ( bOn != bDisplay )
      95           0 :             xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
      96             :     }
      97         176 :     if (bLeft)
      98          88 :         sCont = sContentLeft;
      99             :     else
     100          88 :         sCont = sContent;
     101         176 :     xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
     102         176 : }
     103             : 
     104         352 : XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
     105             : {
     106         352 : }
     107             : 
     108         110 : SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
     109             :     sal_uInt16 nPrefix,
     110             :     const OUString& rLocalName,
     111             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     112             : {
     113         110 :     SvXMLImportContext *pContext(0);
     114             : 
     115         176 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     116          66 :         IsXMLToken(rLocalName, XML_P))
     117             :     {
     118          66 :         if (!xTextCursor.is())
     119             :         {
     120          66 :             if( xHeaderFooterContent.is() )
     121             :             {
     122          66 :                 uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
     123          66 :                 xText->setString(sEmpty);
     124          66 :                 xTextCursor.set(xText->createTextCursor());
     125          66 :                 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     126          66 :                 GetImport().GetTextImport()->SetCursor( xTextCursor );
     127          66 :                 bContainsCenter = true;
     128             :             }
     129             :         }
     130             :         pContext =
     131          66 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     132             :                                                                     nPrefix,
     133             :                                                                     rLocalName,
     134         132 :                                                                     xAttrList);
     135             :     }
     136             :     else
     137             :     {
     138          44 :         if (nPrefix == XML_NAMESPACE_STYLE)
     139             :         {
     140          44 :             if (xHeaderFooterContent.is())
     141             :             {
     142          44 :                 uno::Reference < text::XText > xText;
     143          44 :                 if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
     144             :                 {
     145          22 :                     xText.set(xHeaderFooterContent->getLeftText());
     146          22 :                     bContainsLeft = true;
     147             :                 }
     148          22 :                 else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
     149             :                 {
     150           0 :                     xText.set(xHeaderFooterContent->getCenterText());
     151           0 :                     bContainsCenter = true;
     152             :                 }
     153          22 :                 else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
     154             :                 {
     155          22 :                     xText.set(xHeaderFooterContent->getRightText());
     156          22 :                     bContainsRight = true;
     157             :                 }
     158          44 :                 if (xText.is())
     159             :                 {
     160          44 :                     xText->setString(sEmpty);
     161             :                     //SvXMLImport aSvXMLImport( GetImport() );
     162          44 :                     uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
     163          44 :                     pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xAttrList, xTempTextCursor);
     164          44 :                 }
     165             :             }
     166             :         }
     167             :     }
     168         110 :     if( !pContext )
     169           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     170             : 
     171         110 :     return pContext;
     172             : }
     173             : 
     174         176 : void XMLTableHeaderFooterContext::EndElement()
     175             : {
     176         176 :     if( GetImport().GetTextImport()->GetCursor().is() )
     177             :     {
     178             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     179          66 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     180             :         {
     181         132 :             GetImport().GetTextImport()->GetText()->insertString(
     182         132 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     183         132 :                 true );
     184             :         }
     185          66 :         GetImport().GetTextImport()->ResetCursor();
     186             :     }
     187         176 :     if (xOldTextCursor.is())
     188           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     189         176 :     if (xHeaderFooterContent.is())
     190             :     {
     191         176 :         if (!bContainsLeft)
     192         154 :             xHeaderFooterContent->getLeftText()->setString(sEmpty);
     193         176 :         if (!bContainsCenter)
     194         110 :             xHeaderFooterContent->getCenterText()->setString(sEmpty);
     195         176 :         if (!bContainsRight)
     196         154 :             xHeaderFooterContent->getRightText()->setString(sEmpty);
     197             : 
     198         176 :         xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
     199             :     }
     200         176 : }
     201             : 
     202           0 : TYPEINIT1( XMLHeaderFooterRegionContext, SvXMLImportContext );
     203             : 
     204          44 : XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
     205             :                        const OUString& rLName,
     206             :                        const uno::Reference<
     207             :                             xml::sax::XAttributeList > & /* xAttrList */,
     208             :                        uno::Reference< text::XTextCursor >& xCursor ) :
     209             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     210          44 :     xTextCursor ( xCursor )
     211             : {
     212          44 :     xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     213          44 :     GetImport().GetTextImport()->SetCursor( xTextCursor );
     214          44 : }
     215             : 
     216          88 : XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
     217             : {
     218          88 : }
     219             : 
     220          44 : SvXMLImportContext *XMLHeaderFooterRegionContext::CreateChildContext(
     221             :     sal_uInt16 nPrefix,
     222             :     const OUString& rLocalName,
     223             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     224             : {
     225          44 :     SvXMLImportContext *pContext(0);
     226             : 
     227          88 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     228          44 :         IsXMLToken(rLocalName, XML_P))
     229             :     {
     230             :         pContext =
     231          44 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     232             :                                                                     nPrefix,
     233             :                                                                     rLocalName,
     234          88 :                                                                     xAttrList);
     235             :     }
     236          44 :     if( !pContext )
     237           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     238             : 
     239          44 :     return pContext;
     240             : }
     241             : 
     242          44 : void XMLHeaderFooterRegionContext::EndElement()
     243             : {
     244          44 :     if( GetImport().GetTextImport()->GetCursor().is() )
     245             :     {
     246             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     247          44 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     248             :         {
     249          44 :             OUString sEmpty;
     250          88 :             GetImport().GetTextImport()->GetText()->insertString(
     251          88 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     252         132 :                 true );
     253             :         }
     254          44 :         GetImport().GetTextImport()->ResetCursor();
     255             :     }
     256          44 :     if (xOldTextCursor.is())
     257           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     258          44 : }
     259             : 
     260             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10