1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir #include "vbaparagraph.hxx" 24cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 25cdf0e10cSrcweir #include <tools/diagnose_ex.h> 26cdf0e10cSrcweir #include "vbarange.hxx" 27cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 28cdf0e10cSrcweir 29cdf0e10cSrcweir using namespace ::ooo::vba; 30cdf0e10cSrcweir using namespace ::com::sun::star; 31cdf0e10cSrcweir 32cdf0e10cSrcweir SwVbaParagraph::SwVbaParagraph( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& xDocument, const uno::Reference< text::XTextRange >& xTextRange ) throw ( uno::RuntimeException ) : 33cdf0e10cSrcweir SwVbaParagraph_BASE( rParent, rContext ), mxTextDocument( xDocument ), mxTextRange( xTextRange ) 34cdf0e10cSrcweir { 35cdf0e10cSrcweir } 36cdf0e10cSrcweir 37cdf0e10cSrcweir SwVbaParagraph::~SwVbaParagraph() 38cdf0e10cSrcweir { 39cdf0e10cSrcweir } 40cdf0e10cSrcweir 41cdf0e10cSrcweir uno::Reference< word::XRange > SAL_CALL 42cdf0e10cSrcweir SwVbaParagraph::getRange( ) throw ( uno::RuntimeException ) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, mxTextRange->getStart(), mxTextRange->getEnd(), mxTextRange->getText(), sal_True ) ); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir rtl::OUString& 48cdf0e10cSrcweir SwVbaParagraph::getServiceImplName() 49cdf0e10cSrcweir { 50cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaParagraph") ); 51cdf0e10cSrcweir return sImplName; 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir uno::Sequence< rtl::OUString > 55cdf0e10cSrcweir SwVbaParagraph::getServiceNames() 56cdf0e10cSrcweir { 57cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 58cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir aServiceNames.realloc( 1 ); 61cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Paragraph" ) ); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir return aServiceNames; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir 67cdf0e10cSrcweir //typedef ::cppu::WeakImplHelper1< container::XEnumeration > ParagraphEnumeration_BASE; 68cdf0e10cSrcweir typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > ParagraphCollectionHelper_BASE; 69cdf0e10cSrcweir 70cdf0e10cSrcweir class ParagraphCollectionHelper : public ParagraphCollectionHelper_BASE 71cdf0e10cSrcweir { 72cdf0e10cSrcweir private: 73cdf0e10cSrcweir uno::Reference< text::XTextDocument > mxTextDocument; 74cdf0e10cSrcweir 75cdf0e10cSrcweir uno::Reference< container::XEnumeration > getEnumeration() throw (uno::RuntimeException) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xParEnumAccess( mxTextDocument->getText(), uno::UNO_QUERY_THROW ); 78cdf0e10cSrcweir return xParEnumAccess->createEnumeration(); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir public: 82cdf0e10cSrcweir ParagraphCollectionHelper( const uno::Reference< text::XTextDocument >& xDocument ) throw (uno::RuntimeException): mxTextDocument( xDocument ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir // XElementAccess 86cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return text::XTextRange::static_type(0); } 87cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return sal_True; } 88cdf0e10cSrcweir // XIndexAccess 89cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir sal_Int32 nCount = 0; 92cdf0e10cSrcweir uno::Reference< container::XEnumeration > xParEnum = getEnumeration(); 93cdf0e10cSrcweir while( xParEnum->hasMoreElements() ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW ); 96cdf0e10cSrcweir if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph") ) ) ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir nCount++; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir } 101cdf0e10cSrcweir return nCount; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir if( Index < getCount() ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir sal_Int32 nCount = 0; 108cdf0e10cSrcweir uno::Reference< container::XEnumeration > xParEnum = getEnumeration(); 109cdf0e10cSrcweir while( xParEnum->hasMoreElements() ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW ); 112cdf0e10cSrcweir if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph") ) ) ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir if( Index == nCount ) 115cdf0e10cSrcweir return uno::makeAny( xServiceInfo ); 116cdf0e10cSrcweir nCount++; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir // XEnumerationAccess 123cdf0e10cSrcweir virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir return getEnumeration(); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir }; 128cdf0e10cSrcweir 129cdf0e10cSrcweir SwVbaParagraphs::SwVbaParagraphs( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xDocument ) throw (uno::RuntimeException) : SwVbaParagraphs_BASE( xParent, xContext, new ParagraphCollectionHelper( xDocument ) ), mxTextDocument( xDocument ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir // XEnumerationAccess 134cdf0e10cSrcweir uno::Type 135cdf0e10cSrcweir SwVbaParagraphs::getElementType() throw (uno::RuntimeException) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir return word::XParagraph::static_type(0); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir uno::Reference< container::XEnumeration > 140cdf0e10cSrcweir SwVbaParagraphs::createEnumeration() throw (uno::RuntimeException) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); 143cdf0e10cSrcweir return xEnumerationAccess->createEnumeration(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir uno::Any 147cdf0e10cSrcweir SwVbaParagraphs::createCollectionObject( const css::uno::Any& aSource ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir uno::Reference< text::XTextRange > xTextRange( aSource, uno::UNO_QUERY_THROW ); 150cdf0e10cSrcweir return uno::makeAny( uno::Reference< word::XParagraph >( new SwVbaParagraph( this, mxContext, mxTextDocument, xTextRange ) ) ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir rtl::OUString& 154cdf0e10cSrcweir SwVbaParagraphs::getServiceImplName() 155cdf0e10cSrcweir { 156cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaParagraphs") ); 157cdf0e10cSrcweir return sImplName; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir css::uno::Sequence<rtl::OUString> 161cdf0e10cSrcweir SwVbaParagraphs::getServiceNames() 162cdf0e10cSrcweir { 163cdf0e10cSrcweir static uno::Sequence< rtl::OUString > sNames; 164cdf0e10cSrcweir if ( sNames.getLength() == 0 ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir sNames.realloc( 1 ); 167cdf0e10cSrcweir sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Paragraphs") ); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir return sNames; 170cdf0e10cSrcweir } 171