1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "vbaparagraph.hxx" 28*cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 29*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 30*cdf0e10cSrcweir #include "vbarange.hxx" 31*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir using namespace ::ooo::vba; 34*cdf0e10cSrcweir using namespace ::com::sun::star; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 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 ) : 37*cdf0e10cSrcweir SwVbaParagraph_BASE( rParent, rContext ), mxTextDocument( xDocument ), mxTextRange( xTextRange ) 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir } 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir SwVbaParagraph::~SwVbaParagraph() 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir } 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir uno::Reference< word::XRange > SAL_CALL 46*cdf0e10cSrcweir SwVbaParagraph::getRange( ) throw ( uno::RuntimeException ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, mxTextRange->getStart(), mxTextRange->getEnd(), mxTextRange->getText(), sal_True ) ); 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir rtl::OUString& 52*cdf0e10cSrcweir SwVbaParagraph::getServiceImplName() 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaParagraph") ); 55*cdf0e10cSrcweir return sImplName; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir uno::Sequence< rtl::OUString > 59*cdf0e10cSrcweir SwVbaParagraph::getServiceNames() 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 62*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 65*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Paragraph" ) ); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir return aServiceNames; 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir //typedef ::cppu::WeakImplHelper1< container::XEnumeration > ParagraphEnumeration_BASE; 72*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > ParagraphCollectionHelper_BASE; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir class ParagraphCollectionHelper : public ParagraphCollectionHelper_BASE 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir private: 77*cdf0e10cSrcweir uno::Reference< text::XTextDocument > mxTextDocument; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir uno::Reference< container::XEnumeration > getEnumeration() throw (uno::RuntimeException) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xParEnumAccess( mxTextDocument->getText(), uno::UNO_QUERY_THROW ); 82*cdf0e10cSrcweir return xParEnumAccess->createEnumeration(); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir public: 86*cdf0e10cSrcweir ParagraphCollectionHelper( const uno::Reference< text::XTextDocument >& xDocument ) throw (uno::RuntimeException): mxTextDocument( xDocument ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir // XElementAccess 90*cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return text::XTextRange::static_type(0); } 91*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return sal_True; } 92*cdf0e10cSrcweir // XIndexAccess 93*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir sal_Int32 nCount = 0; 96*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xParEnum = getEnumeration(); 97*cdf0e10cSrcweir while( xParEnum->hasMoreElements() ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW ); 100*cdf0e10cSrcweir if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph") ) ) ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir nCount++; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir return nCount; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir if( Index < getCount() ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir sal_Int32 nCount = 0; 112*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xParEnum = getEnumeration(); 113*cdf0e10cSrcweir while( xParEnum->hasMoreElements() ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW ); 116*cdf0e10cSrcweir if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph") ) ) ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir if( Index == nCount ) 119*cdf0e10cSrcweir return uno::makeAny( xServiceInfo ); 120*cdf0e10cSrcweir nCount++; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir // XEnumerationAccess 127*cdf0e10cSrcweir virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir return getEnumeration(); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir }; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir 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 ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // XEnumerationAccess 138*cdf0e10cSrcweir uno::Type 139*cdf0e10cSrcweir SwVbaParagraphs::getElementType() throw (uno::RuntimeException) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir return word::XParagraph::static_type(0); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir uno::Reference< container::XEnumeration > 144*cdf0e10cSrcweir SwVbaParagraphs::createEnumeration() throw (uno::RuntimeException) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); 147*cdf0e10cSrcweir return xEnumerationAccess->createEnumeration(); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir uno::Any 151*cdf0e10cSrcweir SwVbaParagraphs::createCollectionObject( const css::uno::Any& aSource ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir uno::Reference< text::XTextRange > xTextRange( aSource, uno::UNO_QUERY_THROW ); 154*cdf0e10cSrcweir return uno::makeAny( uno::Reference< word::XParagraph >( new SwVbaParagraph( this, mxContext, mxTextDocument, xTextRange ) ) ); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir rtl::OUString& 158*cdf0e10cSrcweir SwVbaParagraphs::getServiceImplName() 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaParagraphs") ); 161*cdf0e10cSrcweir return sImplName; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir css::uno::Sequence<rtl::OUString> 165*cdf0e10cSrcweir SwVbaParagraphs::getServiceNames() 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > sNames; 168*cdf0e10cSrcweir if ( sNames.getLength() == 0 ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir sNames.realloc( 1 ); 171*cdf0e10cSrcweir sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Paragraphs") ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir return sNames; 174*cdf0e10cSrcweir } 175