1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #include "vbafiledialogitems.hxx"
21 using namespace ::com::sun::star
;
22 using namespace ::ooo::vba
;
26 class FileDialogItemEnumeration
: public ::cppu::WeakImplHelper
< container::XEnumeration
>
28 std::vector
< OUString
> m_sItems
;
29 std::vector
< OUString
>::iterator mIt
;
31 explicit FileDialogItemEnumeration( const std::vector
< OUString
>& rVector
) : m_sItems( rVector
), mIt( m_sItems
.begin() ) {}
32 virtual sal_Bool SAL_CALL
hasMoreElements() override
34 return ( mIt
!= m_sItems
.end() );
36 virtual uno::Any SAL_CALL
nextElement() override
38 if( !hasMoreElements() )
39 throw container::NoSuchElementException();
40 OUString sPath
= *mIt
++;
41 return uno::makeAny( sPath
);
47 ScVbaFileDialogSelectedItems::ScVbaFileDialogSelectedItems(
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
>() )
57 ScVbaFileDialogSelectedItems::getElementType()
59 return cppu::UnoType
<OUString
>::get();
62 uno::Reference
< container::XEnumeration
>
63 ScVbaFileDialogSelectedItems::createEnumeration()
65 return uno::Reference
< container::XEnumeration
>( new FileDialogItemEnumeration( m_sItems
) );
69 ScVbaFileDialogSelectedItems::createCollectionObject( const uno::Any
& aSource
)
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");
77 OUString sPath
= m_sItems
[nPosition
];
78 return uno::makeAny( sPath
);
83 ScVbaFileDialogSelectedItems::Item( const uno::Any
& aIndex
, const uno::Any
& /*aIndex*/ )
85 sal_Int32 nPosition
= -1;
88 --nPosition
; // vba indexing starts with 1
90 if( nPosition
< 0 || nPosition
>= getCount() )
92 throw uno::RuntimeException();
95 return createCollectionObject( uno::makeAny( nPosition
) );
98 sal_Int32
ScVbaFileDialogSelectedItems::getCount()
100 return m_sItems
.size();
105 ScVbaFileDialogSelectedItems::getServiceImplName()
107 return "ScVbaFileDialogSelectedItems";
110 uno::Sequence
<OUString
>
111 ScVbaFileDialogSelectedItems::getServiceNames()
113 static uno::Sequence
< OUString
> const aServiceNames
115 "ooo.vba.FileDialogSelectedItems"
117 return aServiceNames
;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */