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

Generated by: LCOV version 1.10