LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbarevisions.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 72 1.4 %
Date: 2014-11-03 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 "vbarevisions.hxx"
      20             : #include "vbarevision.hxx"
      21             : #include <cppuhelper/implbase2.hxx>
      22             : #include <com/sun/star/document/XRedlinesSupplier.hpp>
      23             : #include <com/sun/star/text/XTextRangeCompare.hpp>
      24             : 
      25             : using namespace ::ooo::vba;
      26             : using namespace ::com::sun::star;
      27             : 
      28             : typedef ::cppu::WeakImplHelper1< container::XEnumeration > RevisionEnumeration_BASE;
      29             : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > RevisionCollectionHelper_BASE;
      30             : typedef std::vector< uno::Reference< beans::XPropertySet > > RevisionMap;
      31             : 
      32           0 : class RedlinesEnumeration : public RevisionEnumeration_BASE
      33             : {
      34             :     RevisionMap mRevisionMap;
      35             :     RevisionMap::iterator mIt;
      36             : public:
      37           0 :     RedlinesEnumeration( const RevisionMap& sMap ) : mRevisionMap( sMap ), mIt( mRevisionMap.begin() ) {}
      38           0 :     virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      39             :     {
      40           0 :         return ( mIt != mRevisionMap.end() );
      41             :     }
      42           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      43             :     {
      44           0 :         if ( !hasMoreElements() )
      45           0 :             throw container::NoSuchElementException();
      46           0 :         uno::Reference< beans::XPropertySet > xRevision( *mIt++ );
      47           0 :         return uno::makeAny( xRevision ) ;
      48             :     }
      49             : };
      50             : 
      51           0 : class RevisionCollectionHelper : public RevisionCollectionHelper_BASE
      52             : {
      53             :     RevisionMap mRevisionMap;
      54             : public:
      55             : RevisionCollectionHelper( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException);
      56             : 
      57             :     // XElementAccess
      58           0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return  cppu::UnoType<beans::XPropertySet>::get(); }
      59           0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return ( !mRevisionMap.empty() ); }
      60             :     // XIndexAccess
      61           0 :     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return mRevisionMap.size(); }
      62           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception ) SAL_OVERRIDE
      63             :     {
      64           0 :         if ( Index < 0 || Index >= getCount() )
      65           0 :             throw lang::IndexOutOfBoundsException();
      66             : 
      67           0 :         return uno::makeAny( mRevisionMap[ Index ] );
      68             : 
      69             :     }
      70             :     // XEnumerationAccess
      71           0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      72             :     {
      73           0 :         return new RedlinesEnumeration( mRevisionMap );
      74             :     }
      75             : };
      76             : 
      77           0 : RevisionCollectionHelper::RevisionCollectionHelper( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException)
      78             :     {
      79           0 :         uno::Reference< text::XTextRangeCompare > xTRC( xTextRange->getText(), uno::UNO_QUERY_THROW );
      80           0 :         uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( xModel, uno::UNO_QUERY_THROW );
      81           0 :         uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
      82           0 :         sal_Int32 nCount = xRedlines->getCount();
      83           0 :         for( sal_Int32 index = 0; index < nCount; index++ )
      84             :         {
      85           0 :             uno::Reference< text::XTextRange > xRedlineRange( xRedlines->getByIndex( index ), uno::UNO_QUERY_THROW );
      86           0 :             if( xTRC->compareRegionStarts( xTextRange, xRedlineRange ) >= 0 && xTRC->compareRegionEnds( xTextRange, xRedlineRange ) <= 0 )
      87             :             {
      88           0 :                 uno::Reference< beans::XPropertySet > xRedlineProps( xRedlineRange, uno::UNO_QUERY_THROW );
      89           0 :                 mRevisionMap.push_back( xRedlineProps );
      90             :             }
      91           0 :         }
      92           0 :     }
      93           0 : class RevisionsEnumeration : public EnumerationHelperImpl
      94             : {
      95             :     uno::Reference< frame::XModel > m_xModel;
      96             : public:
      97           0 :     RevisionsEnumeration( 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 ), m_xModel( xModel ) {}
      98             : 
      99           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
     100             :     {
     101           0 :         uno::Reference< beans::XPropertySet > xRevision( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
     102           0 :         return uno::makeAny( uno::Reference< word::XRevision > ( new SwVbaRevision( m_xParent, m_xContext, m_xModel, xRevision ) ) );
     103             :     }
     104             : 
     105             : };
     106             : 
     107           0 : SwVbaRevisions::SwVbaRevisions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ): SwVbaRevisions_BASE( xParent, xContext, new RevisionCollectionHelper( xModel, xTextRange ) ),  mxModel( xModel )
     108             : {
     109           0 : }
     110             : 
     111           0 : SwVbaRevisions::SwVbaRevisions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< container::XIndexAccess >& xIndexAccess ): SwVbaRevisions_BASE( xParent, xContext, xIndexAccess ),  mxModel( xModel )
     112             : {
     113           0 : }
     114             : 
     115             : // XEnumerationAccess
     116             : uno::Type
     117           0 : SwVbaRevisions::getElementType() throw (uno::RuntimeException)
     118             : {
     119           0 :     return cppu::UnoType<word::XRevision>::get();
     120             : }
     121             : uno::Reference< container::XEnumeration >
     122           0 : SwVbaRevisions::createEnumeration() throw (uno::RuntimeException)
     123             : {
     124           0 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     125           0 :     return new RevisionsEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel );
     126             : }
     127             : 
     128             : uno::Any
     129           0 : SwVbaRevisions::createCollectionObject( const css::uno::Any& aSource )
     130             : {
     131           0 :     uno::Reference< beans::XPropertySet > xRevision( aSource, uno::UNO_QUERY_THROW );
     132           0 :     return uno::makeAny( uno::Reference< word::XRevision > ( new SwVbaRevision( this, mxContext, mxModel, xRevision ) ) );
     133             : }
     134             : 
     135           0 : void SAL_CALL SwVbaRevisions::AcceptAll(  ) throw (css::uno::RuntimeException, std::exception)
     136             : {
     137             :     // First we need to put all the redline into a vector, because if the redline is accepted,
     138             :     // it will auto delete in the document.
     139           0 :     std::vector< uno::Reference< word::XRevision > > aRevisions;
     140           0 :     uno::Reference< container::XEnumeration > xEnumeration = createEnumeration();
     141           0 :     while( xEnumeration->hasMoreElements() )
     142             :     {
     143           0 :         uno::Reference< word::XRevision > xRevision( xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
     144           0 :         aRevisions.push_back( xRevision );
     145           0 :     }
     146             : 
     147           0 :     std::vector< uno::Reference< word::XRevision > >::iterator it = aRevisions.begin();
     148           0 :     for( ; it != aRevisions.end(); ++it )
     149             :     {
     150           0 :         uno::Reference< word::XRevision > xRevision( *it );
     151           0 :         xRevision->Accept();
     152           0 :     }
     153           0 : }
     154             : 
     155           0 : void SAL_CALL SwVbaRevisions::RejectAll(  ) throw (css::uno::RuntimeException, std::exception)
     156             : {
     157           0 :     throw uno::RuntimeException();
     158             : }
     159             : 
     160             : OUString
     161           0 : SwVbaRevisions::getServiceImplName()
     162             : {
     163           0 :     return OUString("SwVbaRevisions");
     164             : }
     165             : 
     166             : css::uno::Sequence<OUString>
     167           0 : SwVbaRevisions::getServiceNames()
     168             : {
     169           0 :     static uno::Sequence< OUString > sNames;
     170           0 :     if ( sNames.getLength() == 0 )
     171             :     {
     172           0 :         sNames.realloc( 1 );
     173           0 :         sNames[0] = "ooo.vba.word.Revisions";
     174             :     }
     175           0 :     return sNames;
     176           6 : }
     177             : 
     178             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10