22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/document/XRedlinesSupplier.hpp>
24#include <com/sun/star/frame/XModel.hpp>
25#include <com/sun/star/text/XTextRangeCompare.hpp>
31typedef std::vector< uno::Reference< beans::XPropertySet > >
RevisionMap;
35class RedlinesEnumeration :
public ::cppu::WeakImplHelper< container::XEnumeration >
38 RevisionMap::iterator mIt;
40 explicit RedlinesEnumeration(
RevisionMap&& sMap ) : mRevisionMap( std::move(sMap) ), mIt( mRevisionMap.begin() ) {}
41 virtual sal_Bool SAL_CALL hasMoreElements( )
override
43 return ( mIt != mRevisionMap.end() );
45 virtual uno::Any SAL_CALL nextElement( )
override
47 if ( !hasMoreElements() )
48 throw container::NoSuchElementException();
49 uno::Reference< beans::XPropertySet > xRevision( *mIt++ );
54class RevisionCollectionHelper :
public ::cppu::WeakImplHelper< container::XIndexAccess,
55 container::XEnumerationAccess >
60RevisionCollectionHelper(
const uno::Reference< frame::XModel >&
xModel,
const uno::Reference< text::XTextRange >& xTextRange );
64 virtual sal_Bool SAL_CALL hasElements( )
override {
return ( !mRevisionMap.empty() ); }
66 virtual ::sal_Int32 SAL_CALL getCount( )
override {
return mRevisionMap.size(); }
67 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
70 throw lang::IndexOutOfBoundsException();
76 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
78 return new RedlinesEnumeration( std::vector(mRevisionMap) );
84RevisionCollectionHelper::RevisionCollectionHelper(
const uno::Reference< frame::XModel >& xModel,
const uno::Reference< text::XTextRange >& xTextRange )
86 uno::Reference< text::XTextRangeCompare > xTRC( xTextRange->getText(), uno::UNO_QUERY_THROW );
87 uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( xModel, uno::UNO_QUERY_THROW );
88 uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
89 sal_Int32
nCount = xRedlines->getCount();
92 uno::Reference< text::XTextRange > xRedlineRange( xRedlines->getByIndex( index ), uno::UNO_QUERY_THROW );
93 if( xTRC->compareRegionStarts( xTextRange, xRedlineRange ) >= 0 && xTRC->compareRegionEnds( xTextRange, xRedlineRange ) <= 0 )
95 uno::Reference< beans::XPropertySet > xRedlineProps( xRedlineRange, uno::UNO_QUERY_THROW );
96 mRevisionMap.push_back( xRedlineProps );
105 uno::Reference< frame::XModel >
m_xModel;
108 RevisionsEnumeration(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration, uno::Reference< frame::XModel > xModel ) :
EnumerationHelperImpl( xParent, xContext, xEnumeration ),
m_xModel(
std::move(
xModel )) {}
110 virtual uno::Any SAL_CALL nextElement( )
override
112 uno::Reference< beans::XPropertySet > xRevision( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
113 return uno::Any( uno::Reference< word::XRevision > (
new SwVbaRevision( m_xParent, m_xContext, m_xModel, xRevision ) ) );
120SwVbaRevisions::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 )
124SwVbaRevisions::SwVbaRevisions(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext > & xContext, uno::Reference< frame::XModel > xModel,
const uno::Reference< container::XIndexAccess >& xIndexAccess ):
SwVbaRevisions_BASE( xParent, xContext, xIndexAccess ),
mxModel(
std::move(
xModel ))
134uno::Reference< container::XEnumeration >
137 uno::Reference< container::XEnumerationAccess > xEnumAccess(
m_xIndexAccess, uno::UNO_QUERY_THROW );
138 return new RevisionsEnumeration(
this,
mxContext, xEnumAccess->createEnumeration(),
mxModel );
144 uno::Reference< beans::XPropertySet > xRevision( aSource, uno::UNO_QUERY_THROW );
152 std::vector< uno::Reference< word::XRevision > > aRevisions;
154 while( xEnumeration->hasMoreElements() )
156 uno::Reference< word::XRevision > xRevision( xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
157 aRevisions.push_back( xRevision );
160 for(
const auto& xRevision : aRevisions )
166 throw uno::RuntimeException();
172 return "SwVbaRevisions";
175css::uno::Sequence<OUString>
178 static uno::Sequence< OUString >
const sNames
180 "ooo.vba.word.Revisions"
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual OUString getServiceImplName() override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Reference< css::frame::XModel > mxModel
virtual void SAL_CALL AcceptAll() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
SwVbaRevisions(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::text::XTextRange > &xTextRange)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual void SAL_CALL RejectAll() override
css::uno::Type const & get()
Reference< frame::XModel > m_xModel
Reference< XModel > xModel
std::vector< uno::Reference< beans::XPropertySet > > RevisionMap