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 
26 namespace {
27 
28 class ListLevelsEnumWrapper : public EnumerationHelper_BASE
29 {
30  SwVbaListLevels* pListLevels;
31  sal_Int32 nIndex;
32 public:
33  explicit ListLevelsEnumWrapper( SwVbaListLevels* pLevels ) : pListLevels( pLevels ), nIndex( 1 ) {}
34  virtual sal_Bool SAL_CALL hasMoreElements( ) override
35  {
36  return ( nIndex <= pListLevels->getCount() );
37  }
38 
39  virtual uno::Any SAL_CALL nextElement( ) override
40  {
41  if ( nIndex <= pListLevels->getCount() )
42  return pListLevels->Item( uno::makeAny( nIndex++ ), uno::Any() );
43  throw container::NoSuchElementException();
44  }
45 };
46 
47 }
48 
49 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 )
50 {
51 }
52 
53 ::sal_Int32 SAL_CALL SwVbaListLevels::getCount()
54 {
55  sal_Int32 nGalleryType = pListHelper->getGalleryType();
56  if( nGalleryType == word::WdListGalleryType::wdBulletGallery
57  || nGalleryType == word::WdListGalleryType::wdNumberGallery )
58  return 1;
59  else if( nGalleryType == word::WdListGalleryType::wdOutlineNumberGallery )
60  return 9;
61  return 0;
62 }
63 
64 uno::Any SAL_CALL SwVbaListLevels::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ )
65 {
66  sal_Int32 nIndex = 0;
67  if( !( Index1 >>= nIndex ) )
68  throw uno::RuntimeException();
69  if( nIndex <=0 || nIndex > getCount() )
70  throw uno::RuntimeException("Index out of bounds" );
71 
72  return uno::makeAny( uno::Reference< word::XListLevel >( new SwVbaListLevel( this, mxContext, pListHelper, nIndex - 1 ) ) );
73 }
74 
75 // XEnumerationAccess
78 {
80 }
81 
82 uno::Reference< container::XEnumeration >
84 {
85  return new ListLevelsEnumWrapper( this );
86 }
87 
89 SwVbaListLevels::createCollectionObject( const css::uno::Any& aSource )
90 {
91  return aSource;
92 }
93 
94 OUString
96 {
97  return "SwVbaListLevels";
98 }
99 
100 css::uno::Sequence<OUString>
102 {
103  static uno::Sequence< OUString > const sNames
104  {
105  "ooo.vba.word.ListLevels"
106  };
107  return sNames;
108 }
109 
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
Reference
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
exports com.sun.star. container
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
SwVbaListHelperRef pListHelper
css::uno::Reference< css::uno::XComponentContext > mxContext
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 OUString getServiceImplName() override
virtual ::sal_Int32 SAL_CALL getCount() override
virtual css::uno::Sequence< OUString > getServiceNames() override