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

Generated by: LCOV version 1.10