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