LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbaheaderfooterhelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 88 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 8 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             : #include "vbaheaderfooterhelper.hxx"
      20             : #include "wordvbahelper.hxx"
      21             : #include <comphelper/processfactory.hxx>
      22             : #include <com/sun/star/frame/XController.hpp>
      23             : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      24             : #include <com/sun/star/text/XTextRangeCompare.hpp>
      25             : #include <com/sun/star/text/XTextRange.hpp>
      26             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      27             : #include <com/sun/star/container/XNameAccess.hpp>
      28             : #include <com/sun/star/lang/XServiceInfo.hpp>
      29             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::ooo::vba;
      33             : 
      34             : #define FIRST_PAGE 1
      35             : 
      36             : // Class HeaderFooterHelper
      37           0 : bool HeaderFooterHelper::isHeaderFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
      38             : {
      39           0 :     return isHeaderFooter( word::getCurrentXText( xModel ) );
      40             : }
      41             : 
      42           0 : bool HeaderFooterHelper::isHeaderFooter( const uno::Reference< text::XText >& xText ) throw (uno::RuntimeException)
      43             : {
      44           0 :     uno::Reference< lang::XServiceInfo > xServiceInfo( xText, uno::UNO_QUERY_THROW );
      45           0 :     OUString aImplName = xServiceInfo->getImplementationName();
      46           0 :     if ( aImplName == "SwXHeadFootText" )
      47           0 :         return true;
      48           0 :     return false;
      49             : }
      50             : 
      51           0 : bool HeaderFooterHelper::isHeader( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
      52             : {
      53           0 :     const uno::Reference< text::XText > xCurrentText = word::getCurrentXText( xModel );
      54           0 :     if( !isHeaderFooter( xCurrentText ) )
      55           0 :         return false;
      56             : 
      57           0 :     OUString aPropIsShared = "HeaderIsShared";
      58           0 :     OUString aPropText = "HeaderText";
      59           0 :     uno::Reference< style::XStyle > xPageStyle = word::getCurrentPageStyle( xModel );
      60           0 :     uno::Reference< beans::XPropertySet > xPageProps( xPageStyle, uno::UNO_QUERY_THROW );
      61           0 :     bool isShared = true;
      62           0 :     xPageProps->getPropertyValue( aPropIsShared ) >>= isShared;
      63           0 :     if( !isShared )
      64             :     {
      65           0 :         uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
      66           0 :         if( 0 == xPageCursor->getPage() % 2 )
      67           0 :             aPropText = "HeaderTextLeft";
      68             :         else
      69           0 :             aPropText = "HeaderTextRight";
      70             :     }
      71             : 
      72           0 :     uno::Reference< text::XText > xHeaderText( xPageProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW );
      73           0 :     uno::Reference< text::XTextRangeCompare > xTRC( xHeaderText, uno::UNO_QUERY_THROW );
      74           0 :     uno::Reference< text::XTextRange > xTR1( xCurrentText, uno::UNO_QUERY_THROW );
      75           0 :     uno::Reference< text::XTextRange > xTR2( xHeaderText, uno::UNO_QUERY_THROW );
      76             :     try
      77             :     {
      78           0 :         if( xTRC->compareRegionStarts( xTR1, xTR2 ) == 0 )
      79           0 :             return true;
      80             :     }
      81           0 :     catch (const lang::IllegalArgumentException&)
      82             :     {
      83           0 :         return false;
      84             :     }
      85             : 
      86           0 :     return false;
      87             : }
      88             : 
      89           0 : bool HeaderFooterHelper::isFirstPageHeader( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
      90             : {
      91           0 :     if( isHeader( xModel ) )
      92             :     {
      93           0 :         uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
      94             :         // FIXME: getPage always returns 1
      95           0 :         sal_Int32 nPage = xPageCursor->getPage();
      96           0 :         return nPage == FIRST_PAGE;
      97             :     }
      98           0 :     return false;
      99             : }
     100             : 
     101           0 : bool HeaderFooterHelper::isEvenPagesHeader( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
     102             : {
     103           0 :     if( isHeader( xModel ) )
     104             :     {
     105           0 :         uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW );
     106           0 :         bool isShared = false;
     107           0 :         xStyleProps->getPropertyValue("HeaderIsShared") >>= isShared;
     108           0 :         if( !isShared )
     109             :         {
     110           0 :             uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
     111           0 :             return ( 0 == xPageCursor->getPage() % 2 );
     112           0 :         }
     113             :     }
     114           0 :     return false;
     115             : }
     116             : 
     117           0 : bool HeaderFooterHelper::isFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
     118             : {
     119           0 :     const uno::Reference< text::XText > xCurrentText = word::getCurrentXText( xModel );
     120           0 :     if( !isHeaderFooter( xCurrentText ) )
     121           0 :         return false;
     122             : 
     123           0 :     OUString aPropIsShared = "FooterIsShared";
     124           0 :     OUString aPropText = "FooterText";
     125           0 :     uno::Reference< style::XStyle > xPageStyle = word::getCurrentPageStyle( xModel );
     126           0 :     uno::Reference< beans::XPropertySet > xPageProps( xPageStyle, uno::UNO_QUERY_THROW );
     127           0 :     bool isShared = true;
     128           0 :     xPageProps->getPropertyValue( aPropIsShared ) >>= isShared;
     129           0 :     if( !isShared )
     130             :     {
     131           0 :         uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
     132           0 :         if( 0 == xPageCursor->getPage() % 2 )
     133           0 :             aPropText = "FooterTextLeft";
     134             :         else
     135           0 :             aPropText = "FooterTextRight";
     136             :     }
     137             : 
     138           0 :     uno::Reference< text::XText > xFooterText( xPageProps->getPropertyValue( aPropText ), uno::UNO_QUERY_THROW );
     139           0 :     uno::Reference< text::XTextRangeCompare > xTRC( xFooterText, uno::UNO_QUERY_THROW );
     140           0 :     uno::Reference< text::XTextRange > xTR1( xCurrentText, uno::UNO_QUERY_THROW );
     141           0 :     uno::Reference< text::XTextRange > xTR2( xFooterText, uno::UNO_QUERY_THROW );
     142             :     try
     143             :     {
     144           0 :         if( xTRC->compareRegionStarts( xTR1, xTR2 ) == 0 )
     145           0 :             return true;
     146             :     }
     147           0 :     catch (const lang::IllegalArgumentException&)
     148             :     {
     149           0 :         return false;
     150             :     }
     151             : 
     152           0 :     return false;
     153             : }
     154             : 
     155           0 : bool HeaderFooterHelper::isFirstPageFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
     156             : {
     157           0 :     if( isFooter( xModel ) )
     158             :     {
     159           0 :         uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
     160           0 :         sal_Int32 nPage = xPageCursor->getPage();
     161           0 :         return nPage == FIRST_PAGE;
     162             :     }
     163           0 :     return false;
     164             : }
     165             : 
     166           0 : bool HeaderFooterHelper::isEvenPagesFooter( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
     167             : {
     168           0 :     if( isFooter( xModel ) )
     169             :     {
     170           0 :         uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW );
     171           0 :         bool isShared = false;
     172           0 :         xStyleProps->getPropertyValue("FooterIsShared") >>= isShared;
     173           0 :         if( !isShared )
     174             :         {
     175           0 :             uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
     176           0 :             return ( 0 == xPageCursor->getPage() % 2 );
     177           0 :         }
     178             :     }
     179           0 :     return false;
     180             : }
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11