1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include "vbafoundfiles.hxx"
23 #include "helperdecl.hxx"
24
25 ///////////////////////////////VbaFoundFilesEnum//////////////////////////////////////////
VbaFoundFilesEnum()26 VbaFoundFilesEnum::VbaFoundFilesEnum() : m_nIndex(0)
27 {
28
29 }
30
VbaFoundFilesEnum(css::uno::Sequence<rtl::OUString> & sFileList)31 VbaFoundFilesEnum::VbaFoundFilesEnum( css::uno::Sequence<rtl::OUString>& sFileList ) : m_nIndex(0), m_sFileList(sFileList)
32 {
33
34 }
35
~VbaFoundFilesEnum()36 VbaFoundFilesEnum::~VbaFoundFilesEnum()
37 {
38
39 }
40
SetFileList(css::uno::Sequence<rtl::OUString> & sFileList)41 void VbaFoundFilesEnum::SetFileList( css::uno::Sequence<rtl::OUString>& sFileList )
42 {
43 m_nIndex = 0;
44 m_sFileList = sFileList;
45 }
46
getCount()47 sal_Int32 SAL_CALL VbaFoundFilesEnum::getCount() throw ( css::uno::RuntimeException )
48 {
49 return m_sFileList.getLength();
50 }
51
getByIndex(sal_Int32 nIndex)52 css::uno::Any SAL_CALL VbaFoundFilesEnum::getByIndex( sal_Int32 nIndex )
53 throw ( css::lang::IndexOutOfBoundsException, css::lang::WrappedTargetException, css::uno::RuntimeException )
54 {
55 if ( nIndex < 0 || nIndex >= getCount() )
56 {
57 throw css::lang::IndexOutOfBoundsException();
58 }
59
60 return css::uno::makeAny( m_sFileList[nIndex] );
61 }
62
getElementType()63 css::uno::Type SAL_CALL VbaFoundFilesEnum::getElementType() throw ( css::uno::RuntimeException )
64 {
65 return getCppuType( (css::uno::Reference< css::container::XIndexAccess >*)0 );
66 }
67
hasElements()68 sal_Bool SAL_CALL VbaFoundFilesEnum::hasElements() throw ( css::uno::RuntimeException )
69 {
70 return ( getCount() != 0 );
71 }
72
hasMoreElements()73 sal_Bool SAL_CALL VbaFoundFilesEnum::hasMoreElements() throw ( css::uno::RuntimeException )
74 {
75 if ( getCount() > m_nIndex )
76 {
77 return sal_True;
78 }
79 return sal_False;
80 }
81
nextElement()82 css::uno::Any SAL_CALL VbaFoundFilesEnum::nextElement() throw ( css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException )
83 {
84 if ( !hasMoreElements() )
85 {
86 throw css::container::NoSuchElementException();
87 }
88
89 return css::uno::makeAny( m_sFileList[m_nIndex++] );
90 }
91
92 ///////////////////////////////VbaFoundFiles//////////////////////////////////////////
93
VbaFoundFiles(const css::uno::Sequence<css::uno::Any> &,const css::uno::Reference<css::uno::XComponentContext> & xContext)94 VbaFoundFiles::VbaFoundFiles( const css::uno::Sequence< css::uno::Any >& /*args*/,
95 const css::uno::Reference< css::uno::XComponentContext >& xContext )
96 : VbaFoundFilesImpl_BASE( css::uno::Reference< ov::XHelperInterface >(),
97 xContext,
98 css::uno::Reference< css::container::XIndexAccess >() )
99 {
100
101 }
102
VbaFoundFiles(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext,const css::uno::Reference<css::container::XIndexAccess> & xIndexAccess)103 VbaFoundFiles::VbaFoundFiles( const css::uno::Reference< ov::XHelperInterface >& xParent,
104 const css::uno::Reference< css::uno::XComponentContext >& xContext,
105 const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess
106 ) : VbaFoundFilesImpl_BASE( xParent, xContext, xIndexAccess )
107 {
108
109 }
110
~VbaFoundFiles()111 VbaFoundFiles::~VbaFoundFiles()
112 {
113
114 }
115
createEnumeration()116 css::uno::Reference< css::container::XEnumeration > VbaFoundFiles::createEnumeration() throw ( css::uno::RuntimeException )
117 {
118 css::uno::Reference< css::container::XEnumeration > xEnumRet( m_xIndexAccess, css::uno::UNO_QUERY );
119 return xEnumRet;
120 }
121
createCollectionObject(const css::uno::Any & aSource)122 css::uno::Any VbaFoundFiles::createCollectionObject( const css::uno::Any& aSource )
123 {
124 return aSource;
125 }
126
File(sal_Int32 nIndex)127 rtl::OUString SAL_CALL VbaFoundFiles::File( sal_Int32 nIndex )
128 throw ( css::uno::RuntimeException )
129 {
130 if ( nIndex < 1 )
131 throw css::lang::IndexOutOfBoundsException();
132 sal_Int32 nCount = m_xIndexAccess->getCount();
133 if ( nIndex > nCount )
134 throw css::lang::IndexOutOfBoundsException();
135 return m_xIndexAccess->getByIndex( nIndex - 1 ).get< rtl::OUString >();
136 }
137
getElementType()138 css::uno::Type VbaFoundFiles::getElementType() throw ( css::uno::RuntimeException )
139 {
140 return ov::XFoundFiles::static_type(0);
141 }
142
getServiceImplName()143 rtl::OUString& VbaFoundFiles::getServiceImplName()
144 {
145 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFoundFiles") );
146 return sImplName;
147 }
148
getServiceNames()149 css::uno::Sequence< rtl::OUString > VbaFoundFiles::getServiceNames()
150 {
151 static css::uno::Sequence< rtl::OUString > aServiceNames;
152 if ( aServiceNames.getLength() == 0 )
153 {
154 aServiceNames.realloc( 1 );
155 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FoundFiles") );
156 }
157 return aServiceNames;
158 }
159