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 <vbahelper/vbahelper.hxx>
21 #include <tools/diagnose_ex.h>
22 #include "vbarange.hxx"
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <cppuhelper/implbase.hxx>
25 
26 using namespace ::ooo::vba;
27 using namespace ::com::sun::star;
28 
29 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 ) :
30  SwVbaParagraph_BASE( rParent, rContext ), mxTextDocument( xDocument ), mxTextRange( xTextRange )
31 {
32 }
33 
35 {
36 }
37 
38 uno::Reference< word::XRange > SAL_CALL
40 {
41  return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, mxTextRange->getStart(), mxTextRange->getEnd(), mxTextRange->getText() ) );
42 }
43 
44 uno::Any SAL_CALL
46 {
47  uno::Reference< word::XRange > xRange = getRange();
48  return xRange->getStyle();
49 }
50 
51 void SAL_CALL
53 {
54  uno::Reference< word::XRange > xRange = getRange();
55  xRange->setStyle( style );
56 }
57 
58 OUString
60 {
61  return "SwVbaParagraph";
62 }
63 
64 uno::Sequence< OUString >
66 {
67  static uno::Sequence< OUString > const aServiceNames
68  {
69  "ooo.vba.word.Paragraph"
70  };
71  return aServiceNames;
72 }
73 
74 namespace {
75 
76 class ParagraphCollectionHelper : public ::cppu::WeakImplHelper< container::XIndexAccess,
77  container::XEnumerationAccess >
78 {
79 private:
80  uno::Reference< text::XTextDocument > mxTextDocument;
81 
83  uno::Reference< container::XEnumeration > getEnumeration()
84  {
85  uno::Reference< container::XEnumerationAccess > xParEnumAccess( mxTextDocument->getText(), uno::UNO_QUERY_THROW );
86  return xParEnumAccess->createEnumeration();
87  }
88 
89 public:
91  explicit ParagraphCollectionHelper( const uno::Reference< text::XTextDocument >& xDocument ): mxTextDocument( xDocument )
92  {
93  }
94  // XElementAccess
95  virtual uno::Type SAL_CALL getElementType( ) override { return cppu::UnoType<text::XTextRange>::get(); }
96  virtual sal_Bool SAL_CALL hasElements( ) override { return true; }
97  // XIndexAccess
98  virtual ::sal_Int32 SAL_CALL getCount( ) override
99  {
100  sal_Int32 nCount = 0;
101  uno::Reference< container::XEnumeration > xParEnum = getEnumeration();
102  while( xParEnum->hasMoreElements() )
103  {
104  uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW );
105  if( xServiceInfo->supportsService("com.sun.star.text.Paragraph") )
106  {
107  nCount++;
108  }
109  }
110  return nCount;
111  }
112  virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
113  {
114  if( Index < getCount() )
115  {
116  sal_Int32 nCount = 0;
117  uno::Reference< container::XEnumeration > xParEnum = getEnumeration();
118  while( xParEnum->hasMoreElements() )
119  {
120  uno::Reference< lang::XServiceInfo > xServiceInfo( xParEnum->nextElement(), uno::UNO_QUERY_THROW );
121  if( xServiceInfo->supportsService("com.sun.star.text.Paragraph") )
122  {
123  if( Index == nCount )
124  return uno::makeAny( xServiceInfo );
125  nCount++;
126  }
127  }
128  }
129  throw lang::IndexOutOfBoundsException();
130  }
131  // XEnumerationAccess
132  virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) override
133  {
134  return getEnumeration();
135  }
136 };
137 
138 }
139 
140 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 )
141 {
142 }
143 
144 // XEnumerationAccess
145 uno::Type
147 {
149 }
150 uno::Reference< container::XEnumeration >
152 {
153  uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
154  return xEnumerationAccess->createEnumeration();
155 }
156 
157 uno::Any
158 SwVbaParagraphs::createCollectionObject( const css::uno::Any& aSource )
159 {
160  uno::Reference< text::XTextRange > xTextRange( aSource, uno::UNO_QUERY_THROW );
161  return uno::makeAny( uno::Reference< word::XParagraph >( new SwVbaParagraph( this, mxContext, mxTextDocument, xTextRange ) ) );
162 }
163 
164 OUString
166 {
167  return "SwVbaParagraphs";
168 }
169 
170 css::uno::Sequence<OUString>
172 {
173  static uno::Sequence< OUString > const sNames
174  {
175  "ooo.vba.word.Paragraphs"
176  };
177  return sNames;
178 }
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::text::XTextRange > mxTextRange
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
SwVbaParagraph(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::text::XTextDocument > &xDocument, const css::uno::Reference< css::text::XTextRange > &xTextRange)
Sequence< OUString > aServiceNames
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any SAL_CALL getStyle() override
int nCount
css::uno::Reference< css::text::XTextDocument > mxTextDocument
virtual css::uno::Type SAL_CALL getElementType() override
virtual OUString getServiceImplName() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
unsigned char sal_Bool
css::uno::Type const & get()
virtual css::uno::Sequence< OUString > getServiceNames() 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)
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual OUString getServiceImplName() override
virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL getRange() override
virtual ~SwVbaParagraph() override
virtual void SAL_CALL setStyle(const css::uno::Any &style) override
struct _ADOIndex Index