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