LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbasections.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 69 0.0 %
Date: 2012-08-25 Functions: 0 26 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 160 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 "vbasections.hxx"
      29                 :            : #include "vbasection.hxx"
      30                 :            : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      31                 :            : #include <com/sun/star/style/XStyle.hpp>
      32                 :            : #include <docsh.hxx>
      33                 :            : #include <doc.hxx>
      34                 :            : #include "wordvbahelper.hxx"
      35                 :            : 
      36                 :            : using namespace ::ooo::vba;
      37                 :            : using namespace ::com::sun::star;
      38                 :            : 
      39                 :            : typedef ::cppu::WeakImplHelper1< container::XEnumeration > SectionEnumeration_BASE;
      40                 :            : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > SectionCollectionHelper_Base;
      41                 :            : typedef std::vector< uno::Reference< beans::XPropertySet > > XSectionVec;
      42                 :            : 
      43         [ #  # ]:          0 : class SectionEnumeration : public SectionEnumeration_BASE
      44                 :            : {
      45                 :            :     XSectionVec mxSections;
      46                 :            :     XSectionVec::iterator mIt;
      47                 :            : 
      48                 :            : public:
      49         [ #  # ]:          0 :     SectionEnumeration( const XSectionVec& rVec ) : mxSections( rVec ), mIt( mxSections.begin() ) {}
      50                 :          0 :     virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
      51                 :            :     {
      52         [ #  # ]:          0 :         return ( mIt != mxSections.end() );
      53                 :            :     }
      54                 :            : 
      55                 :          0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
      56                 :            :     {
      57         [ #  # ]:          0 :         if ( hasMoreElements() )
      58         [ #  # ]:          0 :             return uno::makeAny( *mIt++ );
      59         [ #  # ]:          0 :         throw container::NoSuchElementException();
      60                 :            :     }
      61                 :            : };
      62                 :            : 
      63                 :            : // here I regard pagestyle as section
      64                 :            : class SectionCollectionHelper : public SectionCollectionHelper_Base
      65                 :            : {
      66                 :            : private:
      67                 :            :     uno::Reference< XHelperInterface > mxParent;
      68                 :            :     uno::Reference< uno::XComponentContext > mxContext;
      69                 :            :     uno::Reference< frame::XModel > mxModel;
      70                 :            :     XSectionVec mxSections;
      71                 :            : 
      72                 :            : public:
      73         [ #  # ]:          0 :     SectionCollectionHelper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel )
      74                 :            :     {
      75         [ #  # ]:          0 :         uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( mxModel, uno::UNO_QUERY_THROW );
      76 [ #  # ][ #  # ]:          0 :         uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW );
                 [ #  # ]
      77 [ #  # ][ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xPageStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
      78 [ #  # ][ #  # ]:          0 :         sal_Int32 nCount = xPageStyles->getCount();
      79         [ #  # ]:          0 :         for( sal_Int32 index = 0; index < nCount; ++index )
      80                 :            :         {
      81 [ #  # ][ #  # ]:          0 :             uno::Reference< style::XStyle > xStyle( xPageStyles->getByIndex( index ), uno::UNO_QUERY_THROW );
                 [ #  # ]
      82                 :            :             // only the pagestyles in using are considered
      83 [ #  # ][ #  # ]:          0 :             if( xStyle->isInUse( ) )
                 [ #  # ]
      84                 :            :             {
      85         [ #  # ]:          0 :                 uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW );
      86         [ #  # ]:          0 :                 mxSections.push_back( xPageProps );
      87                 :            :             }
      88                 :          0 :         }
      89                 :          0 :     }
      90                 :            : 
      91         [ #  # ]:          0 :     SectionCollectionHelper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel )
      92                 :            :     {
      93                 :            :         // Hacky implementation of Range.Sections, only support 1 secction
      94         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xRangeProps( xTextRange, uno::UNO_QUERY_THROW );
      95         [ #  # ]:          0 :         uno::Reference< style::XStyle > xStyle = word::getCurrentPageStyle( mxModel, xRangeProps );
      96         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW );
      97         [ #  # ]:          0 :         mxSections.push_back( xPageProps );
      98                 :          0 :     }
      99                 :            : 
     100         [ #  # ]:          0 :     ~SectionCollectionHelper(){}
     101                 :            : 
     102                 :            :     // XIndexAccess
     103                 :          0 :     virtual sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
     104                 :            :     {
     105                 :          0 :         return mxSections.size();
     106                 :            :     }
     107                 :          0 :     virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     108                 :            :     {
     109 [ #  # ][ #  # ]:          0 :         if ( Index < 0 || Index >= getCount() )
         [ #  # ][ #  # ]
     110         [ #  # ]:          0 :             throw css::lang::IndexOutOfBoundsException();
     111                 :            : 
     112         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xPageProps( mxSections[ Index ], uno::UNO_QUERY_THROW );
     113 [ #  # ][ #  # ]:          0 :         return uno::makeAny( uno::Reference< word::XSection >( new SwVbaSection( mxParent,  mxContext, mxModel, xPageProps ) ) );
         [ #  # ][ #  # ]
     114                 :            :     }
     115                 :          0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException)
     116                 :            :     {
     117                 :          0 :         return word::XSection::static_type(0);
     118                 :            :     }
     119                 :          0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException)
     120                 :            :     {
     121                 :          0 :         return sal_True;
     122                 :            :     }
     123                 :            :     // XEnumerationAccess
     124                 :          0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException)
     125                 :            :     {
     126 [ #  # ][ #  # ]:          0 :         return new SectionEnumeration( mxSections );
     127                 :            :     }
     128                 :            : };
     129                 :            : 
     130         [ #  # ]:          0 : class SectionsEnumWrapper : public EnumerationHelperImpl
     131                 :            : {
     132                 :            :     uno::Reference< frame::XModel > mxModel;
     133                 :            : public:
     134                 :          0 :     SectionsEnumWrapper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration,  const uno::Reference< frame::XModel >& xModel  ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), mxModel( xModel ){}
     135                 :            : 
     136                 :          0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     137                 :            :     {
     138 [ #  # ][ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xPageProps( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
                 [ #  # ]
     139 [ #  # ][ #  # ]:          0 :         return uno::makeAny( uno::Reference< word::XSection > ( new SwVbaSection( m_xParent, m_xContext, mxModel, xPageProps ) ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     140                 :            :     }
     141                 :            : };
     142                 :            : 
     143 [ #  # ][ #  # ]:          0 : SwVbaSections::SwVbaSections( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ): SwVbaSections_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new SectionCollectionHelper( xParent, xContext, xModel ) ) ),  mxModel( xModel )
                 [ #  # ]
     144                 :            : {
     145                 :          0 : }
     146                 :            : 
     147 [ #  # ][ #  # ]:          0 : SwVbaSections::SwVbaSections( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ): SwVbaSections_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new SectionCollectionHelper( xParent, xContext, xModel, xTextRange ) ) ),  mxModel( xModel )
                 [ #  # ]
     148                 :            : {
     149                 :          0 : }
     150                 :            : 
     151                 :            : uno::Any SAL_CALL
     152                 :          0 : SwVbaSections::PageSetup( ) throw (uno::RuntimeException)
     153                 :            : {
     154         [ #  # ]:          0 :     if( m_xIndexAccess->getCount() )
     155                 :            :     {
     156                 :            :         // check if the first section is our want
     157 [ #  # ][ #  # ]:          0 :         uno::Reference< word::XSection > xSection( m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     158 [ #  # ][ #  # ]:          0 :         return xSection->PageSetup();
     159                 :            :     }
     160 [ #  # ][ #  # ]:          0 :     throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("There is no section") ), uno::Reference< uno::XInterface >() );
     161                 :            : }
     162                 :            : 
     163                 :            : // XEnumerationAccess
     164                 :            : uno::Type SAL_CALL
     165                 :          0 : SwVbaSections::getElementType() throw (uno::RuntimeException)
     166                 :            : {
     167                 :          0 :     return word::XSection::static_type(0);
     168                 :            : }
     169                 :            : 
     170                 :            : uno::Reference< container::XEnumeration > SAL_CALL
     171                 :          0 : SwVbaSections::createEnumeration() throw (uno::RuntimeException)
     172                 :            : {
     173         [ #  # ]:          0 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     174 [ #  # ][ #  # ]:          0 :     return new SectionsEnumWrapper( this, mxContext, xEnumAccess->createEnumeration(), mxModel );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     175                 :            : }
     176                 :            : 
     177                 :            : uno::Any
     178                 :          0 : SwVbaSections::createCollectionObject( const css::uno::Any& aSource )
     179                 :            : {
     180                 :          0 :     return aSource;
     181                 :            : }
     182                 :            : 
     183                 :            : rtl::OUString
     184                 :          0 : SwVbaSections::getServiceImplName()
     185                 :            : {
     186                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaSections"));
     187                 :            : }
     188                 :            : 
     189                 :            : css::uno::Sequence<rtl::OUString>
     190                 :          0 : SwVbaSections::getServiceNames()
     191                 :            : {
     192 [ #  # ][ #  # ]:          0 :     static uno::Sequence< rtl::OUString > sNames;
         [ #  # ][ #  # ]
     193         [ #  # ]:          0 :     if ( sNames.getLength() == 0 )
     194                 :            :     {
     195                 :          0 :         sNames.realloc( 1 );
     196         [ #  # ]:          0 :         sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Sections") );
     197                 :            :     }
     198                 :          0 :     return sNames;
     199                 :            : }
     200                 :            : 
     201                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10