LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLTableHeaderFooterContext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 101 110 91.8 %
Date: 2014-04-11 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 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         904 : 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         904 :     bContainsCenter(false)
      56             : {
      57         904 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      58        1363 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      59             :     {
      60         459 :         const OUString& rAttrName(xAttrList->getNameByIndex( i ));
      61         918 :         OUString aLName;
      62         459 :         sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
      63         918 :         const OUString& rValue(xAttrList->getValueByIndex( i ));
      64             : 
      65             :         // TODO: use a map here
      66         459 :         if( XML_NAMESPACE_STYLE == nPrefix )
      67             :         {
      68         459 :             if( IsXMLToken(aLName, XML_DISPLAY ) )
      69         459 :                 bDisplay = IsXMLToken(rValue, XML_TRUE);
      70             :         }
      71         459 :     }
      72         904 :     if( bLeft )
      73             :     {
      74         442 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      75             : 
      76         442 :         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         442 :             if( !::cppu::any2bool(xPropSet->getPropertyValue( sShareContent )) )
      85             :                 // share headers
      86           0 :                 xPropSet->setPropertyValue( sShareContent, uno::makeAny(sal_True) );
      87             :         }
      88             :     }
      89             :     else
      90             :     {
      91         462 :         bool bOn(::cppu::any2bool(xPropSet->getPropertyValue( sOn )));
      92         462 :         if ( bOn != bDisplay )
      93          17 :             xPropSet->setPropertyValue( sOn, uno::makeAny(bDisplay) );
      94             :     }
      95         904 :     if (bLeft)
      96         442 :         sCont = sContentLeft;
      97             :     else
      98         462 :         sCont = sContent;
      99         904 :     xPropSet->getPropertyValue( sCont ) >>= xHeaderFooterContent;
     100         904 : }
     101             : 
     102        1808 : XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
     103             : {
     104        1808 : }
     105             : 
     106         593 : SvXMLImportContext *XMLTableHeaderFooterContext::CreateChildContext(
     107             :     sal_uInt16 nPrefix,
     108             :     const OUString& rLocalName,
     109             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     110             : {
     111         593 :     SvXMLImportContext *pContext(0);
     112             : 
     113         936 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     114         343 :         IsXMLToken(rLocalName, XML_P))
     115             :     {
     116         343 :         if (!xTextCursor.is())
     117             :         {
     118         343 :             if( xHeaderFooterContent.is() )
     119             :             {
     120         343 :                 uno::Reference < text::XText > xText(xHeaderFooterContent->getCenterText());
     121         343 :                 xText->setString(sEmpty);
     122         343 :                 xTextCursor.set(xText->createTextCursor());
     123         343 :                 xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     124         343 :                 GetImport().GetTextImport()->SetCursor( xTextCursor );
     125         343 :                 bContainsCenter = true;
     126             :             }
     127             :         }
     128             :         pContext =
     129         343 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     130             :                                                                     nPrefix,
     131             :                                                                     rLocalName,
     132         686 :                                                                     xAttrList);
     133             :     }
     134             :     else
     135             :     {
     136         250 :         if (nPrefix == XML_NAMESPACE_STYLE)
     137             :         {
     138         250 :             if (xHeaderFooterContent.is())
     139             :             {
     140         250 :                 uno::Reference < text::XText > xText;
     141         250 :                 if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
     142             :                 {
     143         119 :                     xText.set(xHeaderFooterContent->getLeftText());
     144         119 :                     bContainsLeft = true;
     145             :                 }
     146         131 :                 else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
     147             :                 {
     148          12 :                     xText.set(xHeaderFooterContent->getCenterText());
     149          12 :                     bContainsCenter = true;
     150             :                 }
     151         119 :                 else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
     152             :                 {
     153         119 :                     xText.set(xHeaderFooterContent->getRightText());
     154         119 :                     bContainsRight = true;
     155             :                 }
     156         250 :                 if (xText.is())
     157             :                 {
     158         250 :                     xText->setString(sEmpty);
     159             :                     //SvXMLImport aSvXMLImport( GetImport() );
     160         250 :                     uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
     161         250 :                     pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xAttrList, xTempTextCursor);
     162         250 :                 }
     163             :             }
     164             :         }
     165             :     }
     166         593 :     if( !pContext )
     167           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     168             : 
     169         593 :     return pContext;
     170             : }
     171             : 
     172         904 : void XMLTableHeaderFooterContext::EndElement()
     173             : {
     174         904 :     if( GetImport().GetTextImport()->GetCursor().is() )
     175             :     {
     176             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     177         343 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     178             :         {
     179         686 :             GetImport().GetTextImport()->GetText()->insertString(
     180         686 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     181         686 :                 true );
     182             :         }
     183         343 :         GetImport().GetTextImport()->ResetCursor();
     184             :     }
     185         904 :     if (xOldTextCursor.is())
     186           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     187         904 :     if (xHeaderFooterContent.is())
     188             :     {
     189         904 :         if (!bContainsLeft)
     190         785 :             xHeaderFooterContent->getLeftText()->setString(sEmpty);
     191         904 :         if (!bContainsCenter)
     192         549 :             xHeaderFooterContent->getCenterText()->setString(sEmpty);
     193         904 :         if (!bContainsRight)
     194         785 :             xHeaderFooterContent->getRightText()->setString(sEmpty);
     195             : 
     196         904 :         xPropSet->setPropertyValue( sCont, uno::makeAny(xHeaderFooterContent) );
     197             :     }
     198         904 : }
     199             : 
     200           0 : TYPEINIT1( XMLHeaderFooterRegionContext, SvXMLImportContext );
     201             : 
     202         250 : 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         250 :     xTextCursor ( xCursor )
     209             : {
     210         250 :     xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
     211         250 :     GetImport().GetTextImport()->SetCursor( xTextCursor );
     212         250 : }
     213             : 
     214         500 : XMLHeaderFooterRegionContext::~XMLHeaderFooterRegionContext()
     215             : {
     216         500 : }
     217             : 
     218         258 : SvXMLImportContext *XMLHeaderFooterRegionContext::CreateChildContext(
     219             :     sal_uInt16 nPrefix,
     220             :     const OUString& rLocalName,
     221             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     222             : {
     223         258 :     SvXMLImportContext *pContext(0);
     224             : 
     225         516 :     if ((nPrefix == XML_NAMESPACE_TEXT) &&
     226         258 :         IsXMLToken(rLocalName, XML_P))
     227             :     {
     228             :         pContext =
     229         258 :             GetImport().GetTextImport()->CreateTextChildContext(GetImport(),
     230             :                                                                     nPrefix,
     231             :                                                                     rLocalName,
     232         516 :                                                                     xAttrList);
     233             :     }
     234         258 :     if( !pContext )
     235           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     236             : 
     237         258 :     return pContext;
     238             : }
     239             : 
     240         250 : void XMLHeaderFooterRegionContext::EndElement()
     241             : {
     242         250 :     if( GetImport().GetTextImport()->GetCursor().is() )
     243             :     {
     244             :         //GetImport().GetTextImport()->GetCursor()->gotoEnd(sal_False);
     245         250 :         if( GetImport().GetTextImport()->GetCursor()->goLeft( 1, true ) )
     246             :         {
     247         250 :             OUString sEmpty;
     248         500 :             GetImport().GetTextImport()->GetText()->insertString(
     249         500 :                 GetImport().GetTextImport()->GetCursorAsRange(), sEmpty,
     250         750 :                 true );
     251             :         }
     252         250 :         GetImport().GetTextImport()->ResetCursor();
     253             :     }
     254         250 :     if (xOldTextCursor.is())
     255           0 :         GetImport().GetTextImport()->SetCursor(xOldTextCursor);
     256         250 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10