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
20#include <o3tl/safeint.hxx>
21
23
24using namespace ::com::sun::star;
25using namespace ::ooo::vba;
26
27namespace {
28
29class FileDialogItemEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration >
30{
31 std::vector< OUString > m_sItems;
32 std::vector< OUString >::iterator mIt;
33public:
34 explicit FileDialogItemEnumeration( std::vector< OUString >&& rVector ) : m_sItems( std::move(rVector) ), mIt( m_sItems.begin() ) {}
35 virtual sal_Bool SAL_CALL hasMoreElements() override
36 {
37 return ( mIt != m_sItems.end() );
38 }
39 virtual uno::Any SAL_CALL nextElement() override
40 {
41 if( !hasMoreElements() )
42 throw container::NoSuchElementException();
43 OUString sPath = *mIt++;
44 return uno::Any( sPath );
45 }
46};
47
48}
49
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)) {}
56
57
58// XEnumerationAccess
59uno::Type SAL_CALL
61{
63}
64
65uno::Reference< container::XEnumeration >
67{
68 return uno::Reference< container::XEnumeration >( new FileDialogItemEnumeration( std::vector(m_sItems) ) );
69}
70
73{
74 sal_Int32 nPosition = -1;
75 if (!(aSource >>= nPosition))
76 throw uno::RuntimeException("not an sal_Int32");
77 if (nPosition < 0 || o3tl::make_unsigned(nPosition) >= m_sItems.size())
78 throw uno::RuntimeException("out of range");
79
80 OUString sPath = m_sItems[nPosition];
81 return uno::Any( sPath );
82}
83
84// Methods
85uno::Any SAL_CALL
86ScVbaFileDialogSelectedItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex*/ )
87{
88 sal_Int32 nPosition = -1;
89 aIndex >>= nPosition;
90
91 --nPosition; // vba indexing starts with 1
92
93 if( nPosition < 0 || nPosition >= getCount() )
94 {
95 throw uno::RuntimeException();
96 }
97
98 return createCollectionObject( uno::Any( nPosition ) );
99}
100
102{
103 return m_sItems.size();
104}
105
106// XHelperInterface
107OUString
109{
110 return "ScVbaFileDialogSelectedItems";
111}
112
113uno::Sequence<OUString>
115{
116 static uno::Sequence< OUString > const aServiceNames
117 {
118 "ooo.vba.FileDialogSelectedItems"
119 };
120 return aServiceNames;
121}
122
123/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const std::vector< OUString > m_sItems
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
ScVbaFileDialogSelectedItems(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, std::vector< OUString > &&sItems)
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index, const css::uno::Any &) override
virtual sal_Int32 SAL_CALL getCount() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Type const & get()
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
Reference
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
enumrange< T >::Iterator begin(enumrange< T >)
unsigned char sal_Bool