tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbafiledialogitems.cxx
blob8737ec4e838318349f60fe0ff4585e2bac088b91
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <o3tl/safeint.hxx>
22 #include "vbafiledialogitems.hxx"
24 using namespace ::com::sun::star;
25 using namespace ::ooo::vba;
27 namespace {
29 class FileDialogItemEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration >
31 std::vector< OUString > m_sItems;
32 std::vector< OUString >::iterator mIt;
33 public:
34 explicit FileDialogItemEnumeration( std::vector< OUString >&& rVector ) : m_sItems( std::move(rVector) ), mIt( m_sItems.begin() ) {}
35 virtual sal_Bool SAL_CALL hasMoreElements() override
37 return ( mIt != m_sItems.end() );
39 virtual uno::Any SAL_CALL nextElement() override
41 if( !hasMoreElements() )
42 throw container::NoSuchElementException();
43 OUString sPath = *mIt++;
44 return uno::Any( sPath );
50 ScVbaFileDialogSelectedItems::ScVbaFileDialogSelectedItems(
51 const css::uno::Reference< ov::XHelperInterface >& xParent
52 ,const css::uno::Reference< css::uno::XComponentContext >& xContext
53 ,std::vector< OUString >&& rItems)
54 : FileDialogSelectedItems_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() )
55 , m_sItems(std::move(rItems)) {}
58 // XEnumerationAccess
59 uno::Type SAL_CALL
60 ScVbaFileDialogSelectedItems::getElementType()
62 return cppu::UnoType<OUString>::get();
65 uno::Reference< container::XEnumeration >
66 ScVbaFileDialogSelectedItems::createEnumeration()
68 return uno::Reference< container::XEnumeration >( new FileDialogItemEnumeration( std::vector(m_sItems) ) );
71 uno::Any
72 ScVbaFileDialogSelectedItems::createCollectionObject( const uno::Any& aSource )
74 sal_Int32 nPosition = -1;
75 if (!(aSource >>= nPosition))
76 throw uno::RuntimeException(u"not an sal_Int32"_ustr);
77 if (nPosition < 0 || o3tl::make_unsigned(nPosition) >= m_sItems.size())
78 throw uno::RuntimeException(u"out of range"_ustr);
80 OUString sPath = m_sItems[nPosition];
81 return uno::Any( sPath );
84 // Methods
85 uno::Any SAL_CALL
86 ScVbaFileDialogSelectedItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex*/ )
88 sal_Int32 nPosition = -1;
89 aIndex >>= nPosition;
91 --nPosition; // vba indexing starts with 1
93 if( nPosition < 0 || nPosition >= getCount() )
95 throw uno::RuntimeException();
98 return createCollectionObject( uno::Any( nPosition ) );
101 sal_Int32 ScVbaFileDialogSelectedItems::getCount()
103 return m_sItems.size();
106 // XHelperInterface
107 OUString
108 ScVbaFileDialogSelectedItems::getServiceImplName()
110 return u"ScVbaFileDialogSelectedItems"_ustr;
113 uno::Sequence<OUString>
114 ScVbaFileDialogSelectedItems::getServiceNames()
116 static uno::Sequence< OUString > const aServiceNames
118 u"ooo.vba.FileDialogSelectedItems"_ustr
120 return aServiceNames;
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */