LibreOffice Module sc (master)  1
vbafiledialogitems.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 "vbafiledialogitems.hxx"
20 
21 using namespace ::com::sun::star;
22 using namespace ::ooo::vba;
23 
24 namespace {
25 
26 class FileDialogItemEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration >
27 {
28  std::vector< OUString > m_sItems;
29  std::vector< OUString >::iterator mIt;
30 public:
31  explicit FileDialogItemEnumeration( const std::vector< OUString >& rVector ) : m_sItems( rVector ), mIt( m_sItems.begin() ) {}
32  virtual sal_Bool SAL_CALL hasMoreElements() override
33  {
34  return ( mIt != m_sItems.end() );
35  }
36  virtual uno::Any SAL_CALL nextElement() override
37  {
38  if( !hasMoreElements() )
39  throw container::NoSuchElementException();
40  OUString sPath = *mIt++;
41  return uno::makeAny( sPath );
42  }
43 };
44 
45 }
46 
48  const css::uno::Reference< ov::XHelperInterface >& xParent
49  ,const css::uno::Reference< css::uno::XComponentContext >& xContext
50  ,const std::vector< OUString >& rItems)
51  : FileDialogSelectedItems_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() )
52  , m_sItems(rItems) {}
53 
54 
55 // XEnumerationAccess
56 uno::Type SAL_CALL
58 {
60 }
61 
62 uno::Reference< container::XEnumeration >
64 {
65  return uno::Reference< container::XEnumeration >( new FileDialogItemEnumeration( m_sItems ) );
66 }
67 
70 {
71  sal_Int32 nPosition = -1;
72  if (!(aSource >>= nPosition))
73  throw uno::RuntimeException("not an sal_Int32");
74  if (nPosition < 0 || nPosition >= static_cast<sal_Int32>(m_sItems.size()))
75  throw uno::RuntimeException("out of range");
76 
77  OUString sPath = m_sItems[nPosition];
78  return uno::makeAny( sPath );
79 }
80 
81 // Methods
82 uno::Any SAL_CALL
83 ScVbaFileDialogSelectedItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex*/ )
84 {
85  sal_Int32 nPosition = -1;
86  aIndex >>= nPosition;
87 
88  --nPosition; // vba indexing starts with 1
89 
90  if( nPosition < 0 || nPosition >= getCount() )
91  {
92  throw uno::RuntimeException();
93  }
94 
95  return createCollectionObject( uno::makeAny( nPosition ) );
96 }
97 
99 {
100  return m_sItems.size();
101 }
102 
103 // XHelperInterface
104 OUString
106 {
107  return "ScVbaFileDialogSelectedItems";
108 }
109 
110 uno::Sequence<OUString>
112 {
113  static uno::Sequence< OUString > const aServiceNames
114  {
115  "ooo.vba.FileDialogSelectedItems"
116  };
117  return aServiceNames;
118 }
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index, const css::uno::Any &) override
virtual OUString getServiceImplName() override
ScVbaFileDialogSelectedItems(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const std::vector< OUString > &sItems)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Reference
Sequence< OUString > aServiceNames
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
exports com.sun.star. container
enumrange< T >::Iterator begin(enumrange< T >)
virtual sal_Int32 SAL_CALL getCount() override
virtual css::uno::Type SAL_CALL getElementType() override
unsigned char sal_Bool
css::uno::Type const & get()
virtual css::uno::Sequence< OUString > getServiceNames() override