1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbaparagraph.hxx"
31 #include <vbahelper/vbahelper.hxx>
32 #include <tools/diagnose_ex.h>
33 #include "vbarange.hxx"
34 #include <com/sun/star/lang/XServiceInfo.hpp>
36 using namespace ::ooo::vba
;
37 using namespace ::com::sun::star
;
39 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
) :
40 SwVbaParagraph_BASE( rParent
, rContext
), mxTextDocument( xDocument
), mxTextRange( xTextRange
)
44 SwVbaParagraph::~SwVbaParagraph()
48 uno::Reference
< word::XRange
> SAL_CALL
49 SwVbaParagraph::getRange( ) throw ( uno::RuntimeException
)
51 return uno::Reference
< word::XRange
>( new SwVbaRange( this, mxContext
, mxTextDocument
, mxTextRange
->getStart(), mxTextRange
->getEnd(), mxTextRange
->getText(), sal_True
) );
55 SwVbaParagraph::getServiceImplName()
57 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaParagraph") );
61 uno::Sequence
< rtl::OUString
>
62 SwVbaParagraph::getServiceNames()
64 static uno::Sequence
< rtl::OUString
> aServiceNames
;
65 if ( aServiceNames
.getLength() == 0 )
67 aServiceNames
.realloc( 1 );
68 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Paragraph" ) );
74 //typedef ::cppu::WeakImplHelper1< container::XEnumeration > ParagraphEnumeration_BASE;
75 typedef ::cppu::WeakImplHelper2
< container::XIndexAccess
, container::XEnumerationAccess
> ParagraphCollectionHelper_BASE
;
77 class ParagraphCollectionHelper
: public ParagraphCollectionHelper_BASE
80 uno::Reference
< text::XTextDocument
> mxTextDocument
;
82 uno::Reference
< container::XEnumeration
> getEnumeration() throw (uno::RuntimeException
)
84 uno::Reference
< container::XEnumerationAccess
> xParEnumAccess( mxTextDocument
->getText(), uno::UNO_QUERY_THROW
);
85 return xParEnumAccess
->createEnumeration();
89 ParagraphCollectionHelper( const uno::Reference
< text::XTextDocument
>& xDocument
) throw (uno::RuntimeException
): mxTextDocument( xDocument
)
93 virtual uno::Type SAL_CALL
getElementType( ) throw (uno::RuntimeException
) { return text::XTextRange::static_type(0); }
94 virtual ::sal_Bool SAL_CALL
hasElements( ) throw (uno::RuntimeException
) { return sal_True
; }
96 virtual ::sal_Int32 SAL_CALL
getCount( ) throw (uno::RuntimeException
)
99 uno::Reference
< container::XEnumeration
> xParEnum
= getEnumeration();
100 while( xParEnum
->hasMoreElements() )
102 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xParEnum
->nextElement(), uno::UNO_QUERY_THROW
);
103 if( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph") ) ) )
110 virtual uno::Any SAL_CALL
getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
112 if( Index
< getCount() )
114 sal_Int32 nCount
= 0;
115 uno::Reference
< container::XEnumeration
> xParEnum
= getEnumeration();
116 while( xParEnum
->hasMoreElements() )
118 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xParEnum
->nextElement(), uno::UNO_QUERY_THROW
);
119 if( xServiceInfo
->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph") ) ) )
121 if( Index
== nCount
)
122 return uno::makeAny( xServiceInfo
);
127 throw lang::IndexOutOfBoundsException();
129 // XEnumerationAccess
130 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
createEnumeration( ) throw (uno::RuntimeException
)
132 return getEnumeration();
136 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
)
140 // XEnumerationAccess
142 SwVbaParagraphs::getElementType() throw (uno::RuntimeException
)
144 return word::XParagraph::static_type(0);
146 uno::Reference
< container::XEnumeration
>
147 SwVbaParagraphs::createEnumeration() throw (uno::RuntimeException
)
149 uno::Reference
< container::XEnumerationAccess
> xEnumerationAccess( m_xIndexAccess
, uno::UNO_QUERY_THROW
);
150 return xEnumerationAccess
->createEnumeration();
154 SwVbaParagraphs::createCollectionObject( const css::uno::Any
& aSource
)
156 uno::Reference
< text::XTextRange
> xTextRange( aSource
, uno::UNO_QUERY_THROW
);
157 return uno::makeAny( uno::Reference
< word::XParagraph
>( new SwVbaParagraph( this, mxContext
, mxTextDocument
, xTextRange
) ) );
161 SwVbaParagraphs::getServiceImplName()
163 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaParagraphs") );
167 css::uno::Sequence
<rtl::OUString
>
168 SwVbaParagraphs::getServiceNames()
170 static uno::Sequence
< rtl::OUString
> sNames
;
171 if ( sNames
.getLength() == 0 )
174 sNames
[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Paragraphs") );