LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbatablesofcontents.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-08-25 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 150 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 2008 by Sun Microsystems, Inc.
       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 "vbatablesofcontents.hxx"
      29                 :            : #include "vbatableofcontents.hxx"
      30                 :            : #include "vbarange.hxx"
      31                 :            : #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
      32                 :            : 
      33                 :            : using namespace ::ooo::vba;
      34                 :            : using namespace ::com::sun::star;
      35                 :            : 
      36                 :            : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > TableOfContentsCollectionHelper_Base;
      37                 :            : typedef std::vector< uno::Reference< text::XDocumentIndex > > XTocVec;
      38                 :            : 
      39         [ #  # ]:          0 : class TablesOfContentsEnumWrapper : public EnumerationHelper_BASE
      40                 :            : {
      41                 :            :     uno::Reference< container::XIndexAccess > mxIndexAccess;
      42                 :            :     sal_Int32 nIndex;
      43                 :            : 
      44                 :            : public:
      45                 :          0 :     TablesOfContentsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 )
      46                 :            :     {
      47                 :          0 :     }
      48                 :          0 :     virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
      49                 :            :     {
      50                 :          0 :         return ( nIndex < mxIndexAccess->getCount() );
      51                 :            :     }
      52                 :            : 
      53                 :          0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
      54                 :            :     {
      55         [ #  # ]:          0 :         if( nIndex < mxIndexAccess->getCount() )
      56                 :            :         {
      57                 :          0 :             return mxIndexAccess->getByIndex( nIndex++ );
      58                 :            :         }
      59         [ #  # ]:          0 :         throw container::NoSuchElementException();
      60                 :            :     }
      61                 :            : };
      62                 :            : 
      63                 :            : class TableOfContentsCollectionHelper : public TableOfContentsCollectionHelper_Base
      64                 :            : {
      65                 :            : private:
      66                 :            :     uno::Reference< XHelperInterface > mxParent;
      67                 :            :     uno::Reference< uno::XComponentContext > mxContext;
      68                 :            :     uno::Reference< text::XTextDocument > mxTextDocument;
      69                 :            :     XTocVec maToc;
      70                 :            : 
      71                 :            : public:
      72         [ #  # ]:          0 :     TableOfContentsCollectionHelper( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xDoc ) throw ( uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxTextDocument( xDoc )
      73                 :            :     {
      74         [ #  # ]:          0 :         uno::Reference< text::XDocumentIndexesSupplier > xDocIndexSupp( mxTextDocument, uno::UNO_QUERY_THROW );
      75 [ #  # ][ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xDocIndexes = xDocIndexSupp->getDocumentIndexes();
      76 [ #  # ][ #  # ]:          0 :         sal_Int32 nCount = xDocIndexes->getCount();
      77         [ #  # ]:          0 :         for( sal_Int32 i = 0; i < nCount; i++ )
      78                 :            :         {
      79 [ #  # ][ #  # ]:          0 :             uno::Reference< text::XDocumentIndex > xToc( xDocIndexes->getByIndex(i), uno::UNO_QUERY_THROW );
                 [ #  # ]
      80 [ #  # ][ #  # ]:          0 :             if( xToc->getServiceName() == "com.sun.star.text.ContentIndex" )
                 [ #  # ]
      81                 :            :             {
      82         [ #  # ]:          0 :                 maToc.push_back( xToc );
      83                 :            :             }
      84                 :          0 :         }
      85                 :          0 :     }
      86                 :            : 
      87         [ #  # ]:          0 :     virtual ~TableOfContentsCollectionHelper() {}
      88                 :            : 
      89                 :          0 :     virtual sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
      90                 :            :     {
      91                 :          0 :         return maToc.size();
      92                 :            :     }
      93                 :          0 :     virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
      94                 :            :     {
      95 [ #  # ][ #  # ]:          0 :         if ( Index < 0 || Index >= getCount() )
         [ #  # ][ #  # ]
      96         [ #  # ]:          0 :             throw lang::IndexOutOfBoundsException();
      97                 :            : 
      98         [ #  # ]:          0 :         uno::Reference< text::XDocumentIndex > xToc( maToc[Index], uno::UNO_QUERY_THROW );
      99 [ #  # ][ #  # ]:          0 :         return uno::makeAny( uno::Reference< word::XTableOfContents >( new SwVbaTableOfContents( mxParent, mxContext, mxTextDocument, xToc ) ) );
         [ #  # ][ #  # ]
     100                 :            :     }
     101                 :          0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException)
     102                 :            :     {
     103                 :          0 :         return word::XTableOfContents::static_type(0);
     104                 :            :     }
     105                 :          0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException)
     106                 :            :     {
     107                 :          0 :         return sal_True;
     108                 :            :     }
     109                 :            :     // XEnumerationAccess
     110                 :          0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException)
     111                 :            :     {
     112 [ #  # ][ #  # ]:          0 :         return new TablesOfContentsEnumWrapper( this );
                 [ #  # ]
     113                 :            :     }
     114                 :            : };
     115                 :            : 
     116 [ #  # ][ #  # ]:          0 : SwVbaTablesOfContents::SwVbaTablesOfContents( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xDoc ) throw (uno::RuntimeException) : SwVbaTablesOfContents_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new TableOfContentsCollectionHelper( xParent, xContext, xDoc ) ) ),  mxTextDocument( xDoc )
                 [ #  # ]
     117                 :            : {
     118                 :          0 : }
     119                 :            : 
     120                 :            : uno::Reference< word::XTableOfContents > SAL_CALL
     121                 :          0 : SwVbaTablesOfContents::Add( const uno::Reference< word::XRange >& Range, const uno::Any& /*UseHeadingStyles*/, const uno::Any& /*UpperHeadingLevel*/, const uno::Any& LowerHeadingLevel, const uno::Any& UseFields, const uno::Any& /*TableID*/, const uno::Any& /*RightAlignPageNumbers*/, const uno::Any& /*IncludePageNumbers*/, const uno::Any& /*AddedStyles*/, const uno::Any& /*UseHyperlinks*/, const uno::Any& /*HidePageNumbersInWeb*/, const uno::Any& /*UseOutlineLevels*/ ) throw (uno::RuntimeException)
     122                 :            : {
     123         [ #  # ]:          0 :     uno::Reference< lang::XMultiServiceFactory > xDocMSF( mxTextDocument, uno::UNO_QUERY_THROW );
     124 [ #  # ][ #  # ]:          0 :     uno::Reference< text::XDocumentIndex > xDocumentIndex( xDocMSF->createInstance(  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ContentIndex")) ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     125                 :            : 
     126         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xTocProps( xDocumentIndex, uno::UNO_QUERY_THROW );
     127                 :          0 :     sal_Bool isProtected = sal_False;
     128 [ #  # ][ #  # ]:          0 :     xTocProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsProtected") ), uno::makeAny( isProtected ) );
         [ #  # ][ #  # ]
     129                 :            : 
     130 [ #  # ][ #  # ]:          0 :     uno::Reference< word::XTableOfContents > xToc( new SwVbaTableOfContents( this, mxContext, mxTextDocument, xDocumentIndex ) );
         [ #  # ][ #  # ]
     131                 :            : 
     132                 :          0 :     sal_Int32 nLowerHeadingLevel = 9;
     133         [ #  # ]:          0 :     if( LowerHeadingLevel.hasValue() )
     134                 :          0 :         LowerHeadingLevel >>= nLowerHeadingLevel;
     135 [ #  # ][ #  # ]:          0 :     xToc->setLowerHeadingLevel( nLowerHeadingLevel );
     136                 :            : 
     137                 :          0 :     sal_Bool bUseFields = sal_False;
     138         [ #  # ]:          0 :     if( UseFields.hasValue() )
     139                 :          0 :         UseFields >>= bUseFields;
     140 [ #  # ][ #  # ]:          0 :     xToc->setUseFields( bUseFields );
     141                 :            : 
     142                 :          0 :     sal_Bool bUseOutlineLevels = sal_True;
     143 [ #  # ][ #  # ]:          0 :     xToc->setUseOutlineLevels( bUseOutlineLevels );
     144                 :            : 
     145 [ #  # ][ #  # ]:          0 :     SwVbaRange* pVbaRange = dynamic_cast<SwVbaRange*>( Range.get() );
     146         [ #  # ]:          0 :     if( !pVbaRange )
     147         [ #  # ]:          0 :         throw uno::RuntimeException();
     148                 :            : 
     149         [ #  # ]:          0 :     uno::Reference< text::XTextRange > xTextRange = pVbaRange->getXTextRange();
     150         [ #  # ]:          0 :     uno::Reference< text::XText > xText = pVbaRange->getXText();
     151         [ #  # ]:          0 :     uno::Reference< text::XTextContent > xTextContent( xDocumentIndex, uno::UNO_QUERY_THROW );
     152 [ #  # ][ #  # ]:          0 :     xText->insertTextContent( xTextRange, xTextContent, sal_False );
     153 [ #  # ][ #  # ]:          0 :     xToc->Update();
     154                 :            : 
     155                 :          0 :     return xToc;
     156                 :            : }
     157                 :            : 
     158                 :            : // XEnumerationAccess
     159                 :            : uno::Type
     160                 :          0 : SwVbaTablesOfContents::getElementType() throw (uno::RuntimeException)
     161                 :            : {
     162                 :          0 :     return word::XTableOfContents::static_type(0);
     163                 :            : }
     164                 :            : uno::Reference< container::XEnumeration >
     165                 :          0 : SwVbaTablesOfContents::createEnumeration() throw (uno::RuntimeException)
     166                 :            : {
     167 [ #  # ][ #  # ]:          0 :     return new TablesOfContentsEnumWrapper( m_xIndexAccess );
     168                 :            : }
     169                 :            : 
     170                 :            : uno::Any
     171                 :          0 : SwVbaTablesOfContents::createCollectionObject( const uno::Any& aSource )
     172                 :            : {
     173                 :          0 :     return aSource;
     174                 :            : }
     175                 :            : 
     176                 :            : rtl::OUString
     177                 :          0 : SwVbaTablesOfContents::getServiceImplName()
     178                 :            : {
     179                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaTablesOfContents"));
     180                 :            : }
     181                 :            : 
     182                 :            : uno::Sequence<rtl::OUString>
     183                 :          0 : SwVbaTablesOfContents::getServiceNames()
     184                 :            : {
     185 [ #  # ][ #  # ]:          0 :     static uno::Sequence< rtl::OUString > sNames;
         [ #  # ][ #  # ]
     186         [ #  # ]:          0 :     if ( sNames.getLength() == 0 )
     187                 :            :     {
     188                 :          0 :         sNames.realloc( 1 );
     189         [ #  # ]:          0 :         sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.TablesOfContents") );
     190                 :            :     }
     191                 :          0 :     return sNames;
     192                 :            : }
     193                 :            : 
     194                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10