LibreOffice Module sw (master)  1
vbalisttemplates.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 "vbalisttemplates.hxx"
20 #include "vbalisttemplate.hxx"
21 
22 using namespace ::ooo::vba;
23 using namespace ::com::sun::star;
24 
25 namespace {
26 
27 class ListTemplatesEnumWrapper : public EnumerationHelper_BASE
28 {
29  SwVbaListTemplates* pListTemplates;
30  sal_Int32 nIndex;
31 public:
32  explicit ListTemplatesEnumWrapper( SwVbaListTemplates* pTemplates ) : pListTemplates( pTemplates ), nIndex( 1 ) {}
33  virtual sal_Bool SAL_CALL hasMoreElements( ) override
34  {
35  return ( nIndex <= pListTemplates->getCount() );
36  }
37 
38  virtual uno::Any SAL_CALL nextElement( ) override
39  {
40  if ( nIndex <= pListTemplates->getCount() )
41  return pListTemplates->Item( uno::makeAny( nIndex++ ), uno::Any() );
42  throw container::NoSuchElementException();
43  }
44 };
45 
46 }
47 
48 SwVbaListTemplates::SwVbaListTemplates( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xTextDoc, sal_Int32 nType ) : SwVbaListTemplates_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >() ), mxTextDocument( xTextDoc ), mnGalleryType( nType )
49 {
50 }
51 
52 ::sal_Int32 SAL_CALL SwVbaListTemplates::getCount()
53 {
54  // 3 types of list( bullet, numbered and outline )
55  return 7;
56 }
57 
58 uno::Any SAL_CALL SwVbaListTemplates::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ )
59 {
60  sal_Int32 nIndex = 0;
61  if( !( Index1 >>= nIndex ) )
62  throw uno::RuntimeException();
63  if( nIndex <=0 || nIndex > getCount() )
64  throw uno::RuntimeException("Index out of bounds" );
65 
66  return uno::makeAny( uno::Reference< word::XListTemplate >( new SwVbaListTemplate( this, mxContext, mxTextDocument, mnGalleryType, nIndex ) ) );
67 }
68 
69 // XEnumerationAccess
72 {
74 }
75 
76 uno::Reference< container::XEnumeration >
78 {
79  return new ListTemplatesEnumWrapper( this );
80 }
81 
83 SwVbaListTemplates::createCollectionObject( const css::uno::Any& aSource )
84 {
85  return aSource;
86 }
87 
88 OUString
90 {
91  return "SwVbaListTemplates";
92 }
93 
94 css::uno::Sequence<OUString>
96 {
97  static uno::Sequence< OUString > const sNames
98  {
99  "ooo.vba.word.ListTemplates"
100  };
101  return sNames;
102 }
103 
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
css::uno::Reference< css::text::XTextDocument > mxTextDocument
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
Reference
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
exports com.sun.star. container
virtual ::sal_Int32 SAL_CALL getCount() override
virtual OUString getServiceImplName() override
unsigned char sal_Bool
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Type const & get()
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Sequence< OUString > getServiceNames() override
SwVbaListTemplates(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::text::XTextDocument > &xTextDoc, sal_Int32 nType)
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override