LibreOffice Module sw (master)  1
vbaframes.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 "vbaframes.hxx"
20 #include "vbaframe.hxx"
21 #include <com/sun/star/text/XTextDocument.hpp>
22 #include <com/sun/star/text/XTextViewCursor.hpp>
23 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
24 #include "wordvbahelper.hxx"
25 #include <cppuhelper/implbase.hxx>
26 
27 using namespace ::ooo::vba;
28 using namespace ::com::sun::star;
29 
30 namespace {
31 
32 class FramesEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration >
33 {
34 private:
35  uno::Reference< XHelperInterface > mxParent;
36  uno::Reference< uno::XComponentContext > mxContext;
37  uno::Reference< container::XIndexAccess> mxIndexAccess;
38  uno::Reference< frame::XModel > mxModel;
39  sal_Int32 nCurrentPos;
40 public:
42  FramesEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference< frame::XModel >& xModel ) : mxParent( xParent ), mxContext( xContext), mxIndexAccess( xIndexAccess ), mxModel( xModel ), nCurrentPos(0)
43  {
44  }
45  virtual sal_Bool SAL_CALL hasMoreElements( ) override
46  {
47  return ( nCurrentPos < mxIndexAccess->getCount() );
48  }
49 
50  virtual uno::Any SAL_CALL nextElement( ) override
51  {
52  if ( !hasMoreElements() )
53  throw container::NoSuchElementException();
54  uno::Reference< text::XTextFrame > xTextFrame( mxIndexAccess->getByIndex( nCurrentPos++ ), uno::UNO_QUERY_THROW );
55  return uno::makeAny( uno::Reference< word::XFrame > ( new SwVbaFrame( mxParent, mxContext, mxModel, xTextFrame ) ) );
56  }
57 
58 };
59 
60 }
61 
62 SwVbaFrames::SwVbaFrames( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xFrames, const uno::Reference< frame::XModel >& xModel ): SwVbaFrames_BASE( xParent, xContext, xFrames ), mxModel( xModel )
63 {
64  mxFramesSupplier.set( mxModel, uno::UNO_QUERY_THROW );
65 }
66 // XEnumerationAccess
69 {
71 }
72 
73 uno::Reference< container::XEnumeration >
75 {
76  return new FramesEnumeration( this, mxContext,m_xIndexAccess, mxModel );
77 }
78 
80 SwVbaFrames::createCollectionObject( const css::uno::Any& aSource )
81 {
82  uno::Reference< text::XTextFrame > xTextFrame( aSource, uno::UNO_QUERY_THROW );
83  return uno::makeAny( uno::Reference< word::XFrame > ( new SwVbaFrame( this, mxContext, mxModel, xTextFrame ) ) );
84 }
85 
86 OUString
88 {
89  return "SwVbaFrames";
90 }
91 
92 css::uno::Sequence<OUString>
94 {
95  static uno::Sequence< OUString > const sNames
96  {
97  "ooo.vba.word.Frames"
98  };
99  return sNames;
100 }
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
WeakReference< XInterface > mxParent
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbaframes.cxx:80
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::text::XTextFramesSupplier > mxFramesSupplier
Definition: vbaframes.hxx:32
SwVbaFrames(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xFrames, const css::uno::Reference< css::frame::XModel > &xModel)
Definition: vbaframes.cxx:62
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbaframes.cxx:93
unsigned char sal_Bool
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbaframes.cxx:74
css::uno::Type const & get()
virtual OUString getServiceImplName() override
Definition: vbaframes.cxx:87
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbaframes.cxx:68
Reference< XComponentContext > mxContext