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

Generated by: LCOV version 1.11