xref: /trunk/main/sc/source/ui/vba/vbafiledialogselecteditems.cxx (revision 7a7771fb4d20b857459c676939e2cc2f4dec9635)
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 "vbafiledialogselecteditems.hxx"
23 
24 using namespace ::com::sun::star;
25 
VbaFileDialogSelectedItems(const css::uno::Reference<ooo::vba::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext,const css::uno::Reference<css::container::XIndexAccess> & xIndexAccess)26 VbaFileDialogSelectedItems::VbaFileDialogSelectedItems(
27         const css::uno::Reference< ooo::vba::XHelperInterface >& xParent,
28         const css::uno::Reference< css::uno::XComponentContext >& xContext,
29         const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess )
30     : FileDialogSelectedItems_BASE( xParent, xContext, xIndexAccess )
31 {
32 }
33 
34 
getServiceImplName()35 rtl::OUString& VbaFileDialogSelectedItems::getServiceImplName()
36 {
37     static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFileDialogSelectedItems") );
38     return sImplName;
39 }
40 
getServiceNames()41 css::uno::Sequence< rtl::OUString > VbaFileDialogSelectedItems::getServiceNames()
42 {
43     static uno::Sequence< rtl::OUString > aServiceNames;
44     if ( aServiceNames.getLength() == 0 )
45     {
46         aServiceNames.realloc( 1 );
47         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FileDialogSelectedItems" ) );
48     }
49     return aServiceNames;
50 }
51 
createCollectionObject(const css::uno::Any & aSource)52 css::uno::Any VbaFileDialogSelectedItems::createCollectionObject( const css::uno::Any& aSource )
53 {
54     css::uno::Any aRet;
55     aRet = aSource;
56     return aRet;
57 }
58 
59 
60 css::uno::Type SAL_CALL
getElementType()61 VbaFileDialogSelectedItems::getElementType() throw (css::uno::RuntimeException)
62 {
63     return ooo::vba::XFileDialogSelectedItems::static_type(0);
64 }
65 
66 css::uno::Reference< css::container::XEnumeration > SAL_CALL
createEnumeration()67 VbaFileDialogSelectedItems::createEnumeration() throw (css::uno::RuntimeException)
68 {
69     css::uno::Reference< css::container::XEnumeration > xEnumRet( m_xIndexAccess, css::uno::UNO_QUERY );
70     return xEnumRet;
71 }
72 
73 
74 // VbaFileDialogSelectedObj
75 ////////////////////////////////////////////////////////////////////////////
76 
VbaFileDialogSelectedObj()77 VbaFileDialogSelectedObj::VbaFileDialogSelectedObj()
78 {
79     m_nIndex = 0;
80 }
81 
82 
83 sal_Bool
SetSelectedFile(css::uno::Sequence<rtl::OUString> & sFList)84 VbaFileDialogSelectedObj::SetSelectedFile( css::uno::Sequence< rtl::OUString > &sFList )
85 {
86     m_sFileList = sFList;
87     return sal_True;
88 }
89 
90 sal_Int32 SAL_CALL
getCount()91 VbaFileDialogSelectedObj::getCount() throw ( css::uno::RuntimeException )
92 {
93     sal_Int32 nListCnt = m_sFileList.getLength();
94     return nListCnt;
95 }
96 
getByIndex(sal_Int32 nIndex)97 css::uno::Any SAL_CALL VbaFileDialogSelectedObj::getByIndex( sal_Int32 nIndex )
98     throw ( css::lang::IndexOutOfBoundsException,
99             css::lang::WrappedTargetException,
100             css::uno::RuntimeException )
101 {
102     if ( nIndex < 0 || nIndex >= getCount() )
103     {
104         throw css::lang::IndexOutOfBoundsException();
105     }
106 
107     return uno::makeAny( m_sFileList[nIndex] );
108 }
109 
110 css::uno::Type SAL_CALL
getElementType()111 VbaFileDialogSelectedObj::getElementType()
112     throw ( css::uno::RuntimeException )
113 {
114     return getCppuType( (uno::Reference< com::sun::star::container::XIndexAccess >*)0 );
115 }
116 
117 sal_Bool SAL_CALL
hasElements()118 VbaFileDialogSelectedObj::hasElements()
119     throw ( css::uno::RuntimeException )
120 {
121     return ( getCount() != 0 );
122 }
123 
124 sal_Bool SAL_CALL
hasMoreElements()125 VbaFileDialogSelectedObj::hasMoreElements()
126     throw ( css::uno::RuntimeException )
127 {
128     if ( getCount() > m_nIndex )
129     {
130         return sal_True;
131     }
132     return sal_False;
133 }
134 
135 css::uno::Any SAL_CALL
nextElement()136 VbaFileDialogSelectedObj::nextElement()
137     throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
138 {
139     if ( !hasMoreElements() )
140     {
141         throw container::NoSuchElementException();
142     }
143 
144     return uno::makeAny( m_sFileList[m_nIndex++] );
145 }
146