LibreOffice Module sw (master)  1
vbalistlevels.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 "vbalistlevels.hxx"
20 #include "vbalistlevel.hxx"
21 #include <ooo/vba/word/WdListGalleryType.hpp>
22 
23 using namespace ::ooo::vba;
24 using namespace ::com::sun::star;
25 
27 {
29  sal_Int32 nIndex;
30 public:
31  explicit ListLevelsEnumWrapper( SwVbaListLevels* pLevels ) : pListLevels( pLevels ), nIndex( 1 ) {}
32  virtual sal_Bool SAL_CALL hasMoreElements( ) override
33  {
34  return ( nIndex <= pListLevels->getCount() );
35  }
36 
37  virtual uno::Any SAL_CALL nextElement( ) override
38  {
39  if ( nIndex <= pListLevels->getCount() )
40  return pListLevels->Item( uno::makeAny( nIndex++ ), uno::Any() );
41  throw container::NoSuchElementException();
42  }
43 };
44 
45 SwVbaListLevels::SwVbaListLevels( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, SwVbaListHelperRef const & pHelper ) : SwVbaListLevels_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >() ), pListHelper( pHelper )
46 {
47 }
48 
49 ::sal_Int32 SAL_CALL SwVbaListLevels::getCount()
50 {
51  sal_Int32 nGalleryType = pListHelper->getGalleryType();
52  if( nGalleryType == word::WdListGalleryType::wdBulletGallery
53  || nGalleryType == word::WdListGalleryType::wdNumberGallery )
54  return 1;
55  else if( nGalleryType == word::WdListGalleryType::wdOutlineNumberGallery )
56  return 9;
57  return 0;
58 }
59 
60 uno::Any SAL_CALL SwVbaListLevels::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("Index out of bounds" );
67 
68  return uno::makeAny( uno::Reference< word::XListLevel >( new SwVbaListLevel( this, mxContext, pListHelper, nIndex - 1 ) ) );
69 }
70 
71 // XEnumerationAccess
74 {
76 }
77 
78 uno::Reference< container::XEnumeration >
80 {
81  return new ListLevelsEnumWrapper( this );
82 }
83 
85 SwVbaListLevels::createCollectionObject( const css::uno::Any& aSource )
86 {
87  return aSource;
88 }
89 
90 OUString
92 {
93  return "SwVbaListLevels";
94 }
95 
96 css::uno::Sequence<OUString>
98 {
99  static uno::Sequence< OUString > const sNames
100  {
101  "ooo.vba.word.ListLevels"
102  };
103  return sNames;
104 }
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL hasMoreElements() override
SwVbaListLevels * pListLevels
Reference
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
SwVbaListLevels(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, SwVbaListHelperRef const &pHelper)
unsigned char sal_Bool
css::uno::Type const & get()
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
css::uno::Reference< css::uno::XComponentContext > mxContext
SwVbaListHelperRef const pListHelper
std::shared_ptr< SwVbaListHelper > SwVbaListHelperRef
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
virtual uno::Any SAL_CALL nextElement() override
virtual OUString getServiceImplName() override
virtual ::sal_Int32 SAL_CALL getCount() override
virtual css::uno::Sequence< OUString > getServiceNames() override
ListLevelsEnumWrapper(SwVbaListLevels *pLevels)