LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbaheaderfooterhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 88 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 190 0.0 %

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

Generated by: LCOV version 1.10