22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
34 uno::Reference< container::XIndexAccess > mxIndexAccess;
38 explicit TablesOfContentsEnumWrapper(
const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 )
41 virtual sal_Bool SAL_CALL hasMoreElements( )
override
43 return ( nIndex < mxIndexAccess->getCount() );
46 virtual uno::Any SAL_CALL nextElement( )
override
48 if( nIndex < mxIndexAccess->getCount() )
50 return mxIndexAccess->getByIndex( nIndex++ );
52 throw container::NoSuchElementException();
56 class TableOfContentsCollectionHelper :
public ::cppu::WeakImplHelper< container::XIndexAccess,
57 container::XEnumerationAccess >
60 uno::Reference< XHelperInterface >
mxParent;
61 uno::Reference< uno::XComponentContext >
mxContext;
62 uno::Reference< text::XTextDocument > mxTextDocument;
63 std::vector< uno::Reference< text::XDocumentIndex > > maToc;
67 TableOfContentsCollectionHelper(
const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext > & xContext,
const uno::Reference< text::XTextDocument >& xDoc ): mxParent( xParent ), mxContext( xContext ), mxTextDocument( xDoc )
69 uno::Reference< text::XDocumentIndexesSupplier > xDocIndexSupp( mxTextDocument, uno::UNO_QUERY_THROW );
70 uno::Reference< container::XIndexAccess > xDocIndexes = xDocIndexSupp->getDocumentIndexes();
71 sal_Int32
nCount = xDocIndexes->getCount();
72 for( sal_Int32 i = 0;
i < nCount;
i++ )
74 uno::Reference< text::XDocumentIndex > xToc( xDocIndexes->getByIndex(i), uno::UNO_QUERY_THROW );
75 if( xToc->getServiceName() ==
"com.sun.star.text.ContentIndex" )
77 maToc.push_back( xToc );
82 virtual sal_Int32 SAL_CALL getCount( )
override
86 virtual uno::Any SAL_CALL getByIndex( sal_Int32
Index )
override
89 throw lang::IndexOutOfBoundsException();
91 uno::Reference< text::XDocumentIndex > xToc( maToc[Index], uno::UNO_SET_THROW );
94 virtual uno::Type SAL_CALL getElementType( )
override
98 virtual sal_Bool SAL_CALL hasElements( )
override
103 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
105 return new TablesOfContentsEnumWrapper(
this );
115 uno::Reference< word::XTableOfContents > SAL_CALL
116 SwVbaTablesOfContents::Add(
const uno::Reference< word::XRange >&
Range,
const uno::Any& ,
const uno::Any& ,
const uno::Any& LowerHeadingLevel,
const uno::Any& UseFields,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& )
118 uno::Reference< lang::XMultiServiceFactory > xDocMSF( mxTextDocument, uno::UNO_QUERY_THROW );
119 uno::Reference< text::XDocumentIndex > xDocumentIndex( xDocMSF->createInstance(
"com.sun.star.text.ContentIndex"), uno::UNO_QUERY_THROW );
121 uno::Reference< beans::XPropertySet > xTocProps( xDocumentIndex, uno::UNO_QUERY_THROW );
122 xTocProps->setPropertyValue(
"IsProtected",
uno::Any(
false ) );
124 uno::Reference< word::XTableOfContents > xToc(
new SwVbaTableOfContents(
this, mxContext, mxTextDocument, xDocumentIndex ) );
126 sal_Int32 nLowerHeadingLevel = 9;
128 LowerHeadingLevel >>= nLowerHeadingLevel;
129 xToc->setLowerHeadingLevel( nLowerHeadingLevel );
131 bool bUseFields =
false;
133 UseFields >>= bUseFields;
134 xToc->setUseFields( bUseFields );
136 xToc->setUseOutlineLevels(
true );
140 throw uno::RuntimeException();
142 uno::Reference< text::XTextRange > xTextRange = pVbaRange->
getXTextRange();
143 uno::Reference< text::XText > xText = pVbaRange->
getXText();
144 uno::Reference< text::XTextContent > xTextContent( xDocumentIndex, uno::UNO_QUERY_THROW );
145 xText->insertTextContent( xTextRange, xTextContent,
false );
157 uno::Reference< container::XEnumeration >
172 return "SwVbaTablesOfContents";
175 uno::Sequence<OUString>
178 static uno::Sequence< OUString >
const sNames
180 "ooo.vba.word.TablesOfContents"
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual OUString getServiceImplName() override
SwVbaTablesOfContents(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::text::XTextDocument > &xDoc)
WeakReference< XInterface > mxParent
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
exports com.sun.star. container
const css::uno::Reference< css::text::XText > & getXText() const
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getXTextRange() override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Type const & get()
virtual css::uno::Reference< ::ooo::vba::word::XTableOfContents > SAL_CALL Add(const css::uno::Reference< ::ooo::vba::word::XRange > &Range, const css::uno::Any &UseHeadingStyles, const css::uno::Any &UpperHeadingLevel, const css::uno::Any &LowerHeadingLevel, const css::uno::Any &UseFields, const css::uno::Any &TableID, const css::uno::Any &RightAlignPageNumbers, const css::uno::Any &IncludePageNumbers, const css::uno::Any &AddedStyles, const css::uno::Any &UseHyperlinks, const css::uno::Any &HidePageNumbersInWeb, const css::uno::Any &UseOutlineLevels) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override