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 
26 {
28  sal_Int32 nIndex;
29 public:
30  explicit ListTemplatesEnumWrapper( SwVbaListTemplates* pTemplates ) : pListTemplates( pTemplates ), nIndex( 1 ) {}
31  virtual sal_Bool SAL_CALL hasMoreElements( ) override
32  {
33  return ( nIndex <= pListTemplates->getCount() );
34  }
35 
36  virtual uno::Any SAL_CALL nextElement( ) override
37  {
38  if ( nIndex <= pListTemplates->getCount() )
39  return pListTemplates->Item( uno::makeAny( nIndex++ ), uno::Any() );
40  throw container::NoSuchElementException();
41  }
42 };
43 
44 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 )
45 {
46 }
47 
48 ::sal_Int32 SAL_CALL SwVbaListTemplates::getCount()
49 {
50  // 3 types of list( bullet, numbered and outline )
51  return 7;
52 }
53 
54 uno::Any SAL_CALL SwVbaListTemplates::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ )
55 {
56  sal_Int32 nIndex = 0;
57  if( !( Index1 >>= nIndex ) )
58  throw uno::RuntimeException();
59  if( nIndex <=0 || nIndex > getCount() )
60  throw uno::RuntimeException("Index out of bounds" );
61 
62  return uno::makeAny( uno::Reference< word::XListTemplate >( new SwVbaListTemplate( this, mxContext, mxTextDocument, mnGalleryType, nIndex ) ) );
63 }
64 
65 // XEnumerationAccess
68 {
70 }
71 
72 uno::Reference< container::XEnumeration >
74 {
75  return new ListTemplatesEnumWrapper( this );
76 }
77 
79 SwVbaListTemplates::createCollectionObject( const css::uno::Any& aSource )
80 {
81  return aSource;
82 }
83 
84 OUString
86 {
87  return "SwVbaListTemplates";
88 }
89 
90 css::uno::Sequence<OUString>
92 {
93  static uno::Sequence< OUString > const sNames
94  {
95  "ooo.vba.word.ListTemplates"
96  };
97  return sNames;
98 }
99 
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::text::XTextDocument > mxTextDocument
virtual sal_Bool SAL_CALL hasMoreElements() override
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
Reference
virtual uno::Any SAL_CALL nextElement() override
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
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 * pListTemplates
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
sal_Int32 const mnGalleryType
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
ListTemplatesEnumWrapper(SwVbaListTemplates *pTemplates)