LibreOffice Module sw (master) 1
vbaparagraph.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include "vbaparagraph.hxx"
20#include "vbarange.hxx"
21#include <com/sun/star/lang/XServiceInfo.hpp>
23#include <utility>
24
25using namespace ::ooo::vba;
26using namespace ::com::sun::star;
27
28SwVbaParagraph::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 ))
30{
31}
32
34{
35}
36
37uno::Reference< word::XRange > SAL_CALL
39{
40 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, mxTextRange->getStart(), mxTextRange->getEnd(), mxTextRange->getText() ) );
41}
42
43uno::Any SAL_CALL
45{
46 uno::Reference< word::XRange > xRange = getRange();
47 return xRange->getStyle();
48}
49
50void SAL_CALL
52{
53 uno::Reference< word::XRange > xRange = getRange();
54 xRange->setStyle( style );
55}
56
57OUString
59{
60 return "SwVbaParagraph";
61}
62
63uno::Sequence< OUString >
65{
66 static uno::Sequence< OUString > const aServiceNames
67 {
68 "ooo.vba.word.Paragraph"
69 };
70 return aServiceNames;
71}
72
73namespace {
74
75class ParagraphCollectionHelper : public ::cppu::WeakImplHelper< container::XIndexAccess,
76 container::XEnumerationAccess >
77{
78private:
79 uno::Reference< text::XTextDocument > mxTextDocument;
80
82 uno::Reference< container::XEnumeration > getEnumeration()
83 {
84 uno::Reference< container::XEnumerationAccess > xParEnumAccess( mxTextDocument->getText(), uno::UNO_QUERY_THROW );
85 return xParEnumAccess->createEnumeration();
86 }
87
88public:
90 explicit ParagraphCollectionHelper( uno::Reference< text::XTextDocument > xDocument ): mxTextDocument(std::move( xDocument ))
91 {
92 }
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
98 {
99 sal_Int32 nCount = 0;
100 uno::Reference< container::XEnumeration > xParEnum = getEnumeration();
101 while( xParEnum->hasMoreElements() )
102 {
103 uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW );
104 if( xServiceInfo->supportsService("com.sun.star.text.Paragraph") )
105 {
106 nCount++;
107 }
108 }
109 return nCount;
110 }
111 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
112 {
113 if( Index < getCount() )
114 {
115 sal_Int32 nCount = 0;
116 uno::Reference< container::XEnumeration > xParEnum = getEnumeration();
117 while( xParEnum->hasMoreElements() )
118 {
119 uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW );
120 if( xServiceInfo->supportsService("com.sun.star.text.Paragraph") )
121 {
122 if( Index == nCount )
123 return uno::Any( xServiceInfo );
124 nCount++;
125 }
126 }
127 }
128 throw lang::IndexOutOfBoundsException();
129 }
130 // XEnumerationAccess
131 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) override
132 {
133 return getEnumeration();
134 }
135};
136
137}
138
139SwVbaParagraphs::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 )
140{
141}
142
143// XEnumerationAccess
146{
148}
149uno::Reference< container::XEnumeration >
151{
152 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
153 return xEnumerationAccess->createEnumeration();
154}
155
157SwVbaParagraphs::createCollectionObject( const css::uno::Any& aSource )
158{
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 ) ) );
161}
162
163OUString
165{
166 return "SwVbaParagraphs";
167}
168
169css::uno::Sequence<OUString>
171{
172 static uno::Sequence< OUString > const sNames
173 {
174 "ooo.vba.word.Paragraphs"
175 };
176 return sNames;
177}
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual ~SwVbaParagraph() override
virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL getRange() override
css::uno::Reference< css::text::XTextDocument > mxTextDocument
SwVbaParagraph(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, css::uno::Reference< css::text::XTextDocument > xDocument, css::uno::Reference< css::text::XTextRange > xTextRange)
virtual void SAL_CALL setStyle(const css::uno::Any &style) override
css::uno::Reference< css::text::XTextRange > mxTextRange
virtual OUString getServiceImplName() override
virtual css::uno::Any SAL_CALL getStyle() override
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::text::XTextDocument > mxTextDocument
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
SwVbaParagraphs(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::text::XTextDocument > &xDocument)
virtual css::uno::Type SAL_CALL getElementType() override
virtual OUString getServiceImplName() override
css::uno::Type const & get()
int nCount
Sequence< OUString > aServiceNames
unsigned char sal_Bool