LibreOffice Module sw (master)  1
vbalistgalleries.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 "vbalistgalleries.hxx"
20 #include "vbalistgallery.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 ListGalleriesEnumWrapper : public EnumerationHelper_BASE
29 {
30  SwVbaListGalleries* pListGalleries;
31  sal_Int32 nIndex;
32 public:
33  explicit ListGalleriesEnumWrapper( SwVbaListGalleries* pGalleries ) : pListGalleries( pGalleries ), nIndex( 1 ) {}
34  virtual sal_Bool SAL_CALL hasMoreElements( ) override
35  {
36  return ( nIndex <= pListGalleries->getCount() );
37  }
38 
39  virtual uno::Any SAL_CALL nextElement( ) override
40  {
41  if ( nIndex <= pListGalleries->getCount() )
42  return pListGalleries->Item( uno::makeAny( nIndex++ ), uno::Any() );
43  throw container::NoSuchElementException();
44  }
45 };
46 
47 }
48 
49 SwVbaListGalleries::SwVbaListGalleries( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextDocument >& xTextDoc ) : SwVbaListGalleries_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >() ), mxTextDocument( xTextDoc )
50 {
51 }
52 
53 ::sal_Int32 SAL_CALL SwVbaListGalleries::getCount()
54 {
55  // 3 types of list( bullet, numbered and outline )
56  return 3;
57 }
58 
59 uno::Any SAL_CALL SwVbaListGalleries::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ )
60 {
61  sal_Int32 nIndex = 0;
62  if( Index1 >>= nIndex )
63  {
64  if( nIndex == word::WdListGalleryType::wdBulletGallery
65  || nIndex == word::WdListGalleryType::wdNumberGallery
66  || nIndex == word::WdListGalleryType::wdOutlineNumberGallery )
67  return uno::makeAny( uno::Reference< word::XListGallery >( new SwVbaListGallery( this, mxContext, mxTextDocument, nIndex ) ) );
68  }
69  throw uno::RuntimeException("Index out of bounds" );
70 }
71 
72 // XEnumerationAccess
75 {
77 }
78 
79 uno::Reference< container::XEnumeration >
81 {
82  return new ListGalleriesEnumWrapper( this );
83 }
84 
86 SwVbaListGalleries::createCollectionObject( const css::uno::Any& aSource )
87 {
88  return aSource;
89 }
90 
91 OUString
93 {
94  return "SwVbaListGalleries";
95 }
96 
97 css::uno::Sequence<OUString>
99 {
100  static uno::Sequence< OUString > const sNames
101  {
102  "ooo.vba.word.ListGalleries"
103  };
104  return sNames;
105 }
106 
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
virtual css::uno::Sequence< OUString > getServiceNames() override
Reference
virtual css::uno::Type SAL_CALL getElementType() override
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
exports com.sun.star. container
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual ::sal_Int32 SAL_CALL getCount() override
unsigned char sal_Bool
SwVbaListGalleries(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::text::XTextDocument > &xTextDoc)
css::uno::Type const & get()
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual OUString getServiceImplName() override
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
css::uno::Reference< css::text::XTextDocument > mxTextDocument