android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbaparagraph.cxx
blob19a31279591007a5555cb8fe14e38c6ffab150bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "vbaparagraph.hxx"
20 #include "vbarange.hxx"
21 #include <com/sun/star/lang/XServiceInfo.hpp>
22 #include <cppuhelper/implbase.hxx>
23 #include <utility>
25 using namespace ::ooo::vba;
26 using namespace ::com::sun::star;
28 SwVbaParagraph::SwVbaParagraph( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, uno::Reference< text::XTextDocument > xDocument, uno::Reference< text::XTextRange > xTextRange ) :
29 SwVbaParagraph_BASE( rParent, rContext ), mxTextDocument(std::move( xDocument )), mxTextRange(std::move( xTextRange ))
33 SwVbaParagraph::~SwVbaParagraph()
37 uno::Reference< word::XRange > SAL_CALL
38 SwVbaParagraph::getRange( )
40 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, mxTextRange->getStart(), mxTextRange->getEnd(), mxTextRange->getText() ) );
43 uno::Any SAL_CALL
44 SwVbaParagraph::getStyle( )
46 uno::Reference< word::XRange > xRange = getRange();
47 return xRange->getStyle();
50 void SAL_CALL
51 SwVbaParagraph::setStyle( const uno::Any& style )
53 uno::Reference< word::XRange > xRange = getRange();
54 xRange->setStyle( style );
57 OUString
58 SwVbaParagraph::getServiceImplName()
60 return "SwVbaParagraph";
63 uno::Sequence< OUString >
64 SwVbaParagraph::getServiceNames()
66 static uno::Sequence< OUString > const aServiceNames
68 "ooo.vba.word.Paragraph"
70 return aServiceNames;
73 namespace {
75 class ParagraphCollectionHelper : public ::cppu::WeakImplHelper< container::XIndexAccess,
76 container::XEnumerationAccess >
78 private:
79 uno::Reference< text::XTextDocument > mxTextDocument;
81 /// @throws uno::RuntimeException
82 uno::Reference< container::XEnumeration > getEnumeration()
84 uno::Reference< container::XEnumerationAccess > xParEnumAccess( mxTextDocument->getText(), uno::UNO_QUERY_THROW );
85 return xParEnumAccess->createEnumeration();
88 public:
89 /// @throws uno::RuntimeException
90 explicit ParagraphCollectionHelper( uno::Reference< text::XTextDocument > xDocument ): mxTextDocument(std::move( xDocument ))
93 // XElementAccess
94 virtual uno::Type SAL_CALL getElementType( ) override { return cppu::UnoType<text::XTextRange>::get(); }
95 virtual sal_Bool SAL_CALL hasElements( ) override { return true; }
96 // XIndexAccess
97 virtual ::sal_Int32 SAL_CALL getCount( ) override
99 sal_Int32 nCount = 0;
100 uno::Reference< container::XEnumeration > xParEnum = getEnumeration();
101 while( xParEnum->hasMoreElements() )
103 uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW );
104 if( xServiceInfo->supportsService("com.sun.star.text.Paragraph") )
106 nCount++;
109 return nCount;
111 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
113 if( Index < getCount() )
115 sal_Int32 nCount = 0;
116 uno::Reference< container::XEnumeration > xParEnum = getEnumeration();
117 while( xParEnum->hasMoreElements() )
119 uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW );
120 if( xServiceInfo->supportsService("com.sun.star.text.Paragraph") )
122 if( Index == nCount )
123 return uno::Any( xServiceInfo );
124 nCount++;
128 throw lang::IndexOutOfBoundsException();
130 // XEnumerationAccess
131 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) override
133 return getEnumeration();
139 SwVbaParagraphs::SwVbaParagraphs( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xDocument ) : SwVbaParagraphs_BASE( xParent, xContext, new ParagraphCollectionHelper( xDocument ) ), mxTextDocument( xDocument )
143 // XEnumerationAccess
144 uno::Type
145 SwVbaParagraphs::getElementType()
147 return cppu::UnoType<word::XParagraph>::get();
149 uno::Reference< container::XEnumeration >
150 SwVbaParagraphs::createEnumeration()
152 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
153 return xEnumerationAccess->createEnumeration();
156 uno::Any
157 SwVbaParagraphs::createCollectionObject( const css::uno::Any& aSource )
159 uno::Reference< text::XTextRange > xTextRange( aSource, uno::UNO_QUERY_THROW );
160 return uno::Any( uno::Reference< word::XParagraph >( new SwVbaParagraph( this, mxContext, mxTextDocument, xTextRange ) ) );
163 OUString
164 SwVbaParagraphs::getServiceImplName()
166 return "SwVbaParagraphs";
169 css::uno::Sequence<OUString>
170 SwVbaParagraphs::getServiceNames()
172 static uno::Sequence< OUString > const sNames
174 "ooo.vba.word.Paragraphs"
176 return sNames;
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */