21#include <com/sun/star/frame/XModel.hpp>
22#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23#include <com/sun/star/style/XStyle.hpp>
31typedef std::vector< uno::Reference< beans::XPropertySet > >
XSectionVec;
35class SectionEnumeration :
public ::cppu::WeakImplHelper< container::XEnumeration >
38 XSectionVec::iterator mIt;
41 explicit SectionEnumeration(
XSectionVec&& rVec ) : mxSections( std::move(rVec) ), mIt( mxSections.begin() ) {}
42 virtual sal_Bool SAL_CALL hasMoreElements( )
override
44 return ( mIt != mxSections.end() );
47 virtual uno::Any SAL_CALL nextElement( )
override
49 if ( hasMoreElements() )
51 throw container::NoSuchElementException();
56class SectionCollectionHelper :
public ::cppu::WeakImplHelper< container::XIndexAccess,
57 container::XEnumerationAccess >
60 uno::Reference< XHelperInterface >
mxParent;
61 uno::Reference< uno::XComponentContext >
mxContext;
62 uno::Reference< frame::XModel >
mxModel;
67 SectionCollectionHelper( uno::Reference< XHelperInterface > xParent, uno::Reference< uno::XComponentContext > xContext, uno::Reference< frame::XModel >
xModel ) :
mxParent(std::move( xParent )),
mxContext(std::move( xContext )),
mxModel(std::move(
xModel ))
69 uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp(
mxModel, uno::UNO_QUERY_THROW );
70 uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_SET_THROW );
71 uno::Reference< container::XIndexAccess > xPageStyles( xSytleFamNames->getByName(
"PageStyles"), uno::UNO_QUERY_THROW );
72 sal_Int32
nCount = xPageStyles->getCount();
75 uno::Reference< style::XStyle > xStyle( xPageStyles->getByIndex(
index ), uno::UNO_QUERY_THROW );
77 if( xStyle->isInUse( ) )
79 uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW );
80 mxSections.push_back( xPageProps );
86 SectionCollectionHelper( uno::Reference< XHelperInterface > xParent, uno::Reference< uno::XComponentContext > xContext, uno::Reference< frame::XModel >
xModel,
const uno::Reference< text::XTextRange >& xTextRange ) :
mxParent(std::move( xParent )),
mxContext(std::move( xContext )),
mxModel(std::move(
xModel ))
89 uno::Reference< beans::XPropertySet > xRangeProps( xTextRange, uno::UNO_QUERY_THROW );
91 uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW );
92 mxSections.push_back( xPageProps );
96 virtual sal_Int32 SAL_CALL getCount( )
override
98 return mxSections.size();
100 virtual uno::Any SAL_CALL getByIndex( sal_Int32
Index )
override
103 throw css::lang::IndexOutOfBoundsException();
105 uno::Reference< beans::XPropertySet > xPageProps( mxSections[
Index ], uno::UNO_SET_THROW );
108 virtual uno::Type SAL_CALL getElementType( )
override
112 virtual sal_Bool SAL_CALL hasElements( )
override
117 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
119 return new SectionEnumeration( std::vector(mxSections) );
125 uno::Reference< frame::XModel >
mxModel;
128 SectionsEnumWrapper(
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 ),
mxModel(std::move(
xModel )){}
130 virtual uno::Any SAL_CALL nextElement( )
override
132 uno::Reference< beans::XPropertySet > xPageProps( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
143SwVbaSections::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 )
153 uno::Reference< word::XSection > xSection(
m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW );
154 return xSection->PageSetup();
156 throw uno::RuntimeException(
"There is no section" );
166uno::Reference< container::XEnumeration > SAL_CALL
169 uno::Reference< container::XEnumerationAccess > xEnumAccess(
m_xIndexAccess, uno::UNO_QUERY_THROW );
170 return new SectionsEnumWrapper(
this,
mxContext, xEnumAccess->createEnumeration(),
mxModel );
182 return "SwVbaSections";
185css::uno::Sequence<OUString>
188 static uno::Sequence< OUString >
const sNames
190 "ooo.vba.word.Sections"
Reference< XComponentContext > m_xContext
css::uno::Reference< css::frame::XModel2 > mxModel
unotools::WeakReference< AnimationNode > mxParent
EnumerationHelperImpl(const css::uno::Reference< ov::XHelperInterface > &xParent, css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Reference< css::container::XEnumeration > xEnumeration)
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any SAL_CALL PageSetup() override
css::uno::Reference< css::frame::XModel > mxModel
SwVbaSections(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel)
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual OUString getServiceImplName() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
css::uno::Type const & get()
uno::Reference< style::XStyle > getCurrentPageStyle(const uno::Reference< frame::XModel > &xModel)
Reference< XModel > xModel
std::vector< uno::Reference< beans::XPropertySet > > XSectionVec