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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_fpicker.hxx"
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 #include <osl/diagnose.h>
31 
32 #ifndef _FOLDERPICKER_HXX_
33 #include "folderpicker.hxx"
34 #endif
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include "WinFOPImpl.hxx"
37 
38 //------------------------------------------------------------------------
39 // namespace directives
40 //------------------------------------------------------------------------
41 
42 using com::sun::star::uno::Reference;
43 using com::sun::star::uno::RuntimeException;
44 using com::sun::star::uno::Sequence;
45 using com::sun::star::uno::XInterface;
46 using com::sun::star::lang::XMultiServiceFactory;
47 using com::sun::star::lang::XServiceInfo;
48 using com::sun::star::lang::DisposedException;
49 using com::sun::star::lang::IllegalArgumentException;
50 using rtl::OUString;
51 using osl::MutexGuard;
52 
53 using namespace cppu;
54 using namespace com::sun::star::ui::dialogs;
55 
56 //------------------------------------------------------------------------
57 // defines
58 //------------------------------------------------------------------------
59 
60 #define FOLDERPICKER_IMPL_NAME  "com.sun.star.ui.dialogs.Win32FolderPicker"
61 
62 //------------------------------------------------------------------------
63 // helper functions
64 //------------------------------------------------------------------------
65 
66 namespace
67 {
FolderPicker_getSupportedServiceNames()68 	Sequence< OUString > SAL_CALL FolderPicker_getSupportedServiceNames()
69 	{
70         Sequence< OUString > aRet(1);
71         aRet[0] = OUString::createFromAscii("com.sun.star.ui.dialogs.SystemFolderPicker");
72 		return aRet;
73 	}
74 }
75 
76 //-----------------------------------------------------------------------------------------
77 //
78 //-----------------------------------------------------------------------------------------
79 
CFolderPicker(const Reference<XMultiServiceFactory> & xServiceMgr)80 CFolderPicker::CFolderPicker( const Reference< XMultiServiceFactory >& xServiceMgr ) :
81 	m_xServiceMgr( xServiceMgr )
82 {
83 	m_pFolderPickerImpl = std::auto_ptr< CWinFolderPickerImpl > ( new CWinFolderPickerImpl( this ) );
84 }
85 
86 //-----------------------------------------------------------------------------------------
87 //
88 //-----------------------------------------------------------------------------------------
89 
setTitle(const OUString & aTitle)90 void SAL_CALL CFolderPicker::setTitle( const OUString& aTitle ) throw( RuntimeException )
91 {
92 	OSL_ASSERT( m_pFolderPickerImpl.get( ) );
93 	MutexGuard aGuard( m_aMutex );
94 	m_pFolderPickerImpl->setTitle( aTitle );
95 }
96 
97 //-----------------------------------------------------------------------------------------
98 //
99 //-----------------------------------------------------------------------------------------
100 
setDisplayDirectory(const OUString & aDirectory)101 void SAL_CALL CFolderPicker::setDisplayDirectory( const OUString& aDirectory )
102 	throw( IllegalArgumentException, RuntimeException )
103 {
104 	OSL_ASSERT( m_pFolderPickerImpl.get( ) );
105 	MutexGuard aGuard( m_aMutex );
106 	m_pFolderPickerImpl->setDisplayDirectory( aDirectory );
107 }
108 
109 //-----------------------------------------------------------------------------------------
110 //
111 //-----------------------------------------------------------------------------------------
112 
getDisplayDirectory()113 OUString SAL_CALL CFolderPicker::getDisplayDirectory( )
114 	throw( RuntimeException )
115 {
116 	OSL_ASSERT( m_pFolderPickerImpl.get( ) );
117 	MutexGuard aGuard( m_aMutex );
118 	return m_pFolderPickerImpl->getDisplayDirectory( );
119 }
120 
121 //-----------------------------------------------------------------------------------------
122 //
123 //-----------------------------------------------------------------------------------------
124 
getDirectory()125 OUString SAL_CALL CFolderPicker::getDirectory( ) throw( RuntimeException )
126 {
127     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
128 	MutexGuard aGuard( m_aMutex );
129 	return m_pFolderPickerImpl->getDirectory( );
130 }
131 
132 //-----------------------------------------------------------------------------------------
133 //
134 //-----------------------------------------------------------------------------------------
135 
setDescription(const OUString & aDescription)136 void SAL_CALL CFolderPicker::setDescription( const OUString& aDescription ) throw( RuntimeException )
137 {
138     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
139     MutexGuard aGuard( m_aMutex );
140     m_pFolderPickerImpl->setDescription( aDescription );
141 }
142 
143 //-----------------------------------------------------------------------------------------
144 //
145 //-----------------------------------------------------------------------------------------
146 
execute()147 sal_Int16 SAL_CALL CFolderPicker::execute( )
148 	throw( RuntimeException )
149 {
150 	OSL_ASSERT( m_pFolderPickerImpl.get( ) );
151 
152 	// we should not block in this call else
153 	// in the case of an event the client can'tgetPImplFromHandle( hWnd )
154 	// call another function an we run into a
155 	// deadlock !!!!!
156 	return m_pFolderPickerImpl->execute( );
157 }
158 
159 // -------------------------------------------------
160 // XServiceInfo
161 // -------------------------------------------------
162 
getImplementationName()163 OUString SAL_CALL CFolderPicker::getImplementationName(  )
164 	throw( RuntimeException )
165 {
166 	return OUString::createFromAscii( FOLDERPICKER_IMPL_NAME );
167 }
168 
169 // -------------------------------------------------
170 //	XServiceInfo
171 // -------------------------------------------------
172 
supportsService(const OUString & ServiceName)173 sal_Bool SAL_CALL CFolderPicker::supportsService( const OUString& ServiceName )
174 	throw( RuntimeException )
175 {
176 	Sequence < OUString > SupportedServicesNames = FolderPicker_getSupportedServiceNames();
177 
178 	for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
179 		if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
180 			return sal_True;
181 
182 	return sal_False;
183 }
184 
185 // -------------------------------------------------
186 //	XServiceInfo
187 // -------------------------------------------------
188 
getSupportedServiceNames()189 Sequence< OUString > SAL_CALL CFolderPicker::getSupportedServiceNames(	 )
190 	throw( RuntimeException )
191 {
192 	return FolderPicker_getSupportedServiceNames();
193 }
194 
195 // -------------------------------------------------
196 //	XCancellable
197 // -------------------------------------------------
198 
cancel()199 void SAL_CALL CFolderPicker::cancel( )
200 	throw(RuntimeException)
201 {
202     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
203     MutexGuard aGuard( m_aMutex );
204     m_pFolderPickerImpl->cancel( );
205 }
206 
207 //------------------------------------------------
208 // overwrite base class method, which is called
209 // by base class dispose function
210 //------------------------------------------------
211 
disposing()212 void SAL_CALL CFolderPicker::disposing()
213 {
214 }
215 
216