xref: /trunk/main/fpicker/source/win32/folderpicker/FolderPicker.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
30 
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
34 #include <osl/diagnose.h>
35 
36 #ifndef _FOLDERPICKER_HXX_
37 #include "folderpicker.hxx"
38 #endif
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include "WinFOPImpl.hxx"
41 
42 //------------------------------------------------------------------------
43 // namespace directives
44 //------------------------------------------------------------------------
45 
46 using com::sun::star::uno::Reference;
47 using com::sun::star::uno::RuntimeException;
48 using com::sun::star::uno::Sequence;
49 using com::sun::star::uno::XInterface;
50 using com::sun::star::lang::XMultiServiceFactory;
51 using com::sun::star::lang::XServiceInfo;
52 using com::sun::star::lang::DisposedException;
53 using com::sun::star::lang::IllegalArgumentException;
54 using rtl::OUString;
55 using osl::MutexGuard;
56 
57 using namespace cppu;
58 using namespace com::sun::star::ui::dialogs;
59 
60 //------------------------------------------------------------------------
61 // defines
62 //------------------------------------------------------------------------
63 
64 #define FOLDERPICKER_IMPL_NAME  "com.sun.star.ui.dialogs.Win32FolderPicker"
65 
66 //------------------------------------------------------------------------
67 // helper functions
68 //------------------------------------------------------------------------
69 
70 namespace
71 {
72     Sequence< OUString > SAL_CALL FolderPicker_getSupportedServiceNames()
73     {
74         Sequence< OUString > aRet(1);
75         aRet[0] = OUString::createFromAscii("com.sun.star.ui.dialogs.SystemFolderPicker");
76         return aRet;
77     }
78 }
79 
80 //-----------------------------------------------------------------------------------------
81 //
82 //-----------------------------------------------------------------------------------------
83 
84 CFolderPicker::CFolderPicker( const Reference< XMultiServiceFactory >& xServiceMgr ) :
85     m_xServiceMgr( xServiceMgr )
86 {
87     m_pFolderPickerImpl = std::auto_ptr< CWinFolderPickerImpl > ( new CWinFolderPickerImpl( this ) );
88 }
89 
90 //-----------------------------------------------------------------------------------------
91 //
92 //-----------------------------------------------------------------------------------------
93 
94 void SAL_CALL CFolderPicker::setTitle( const OUString& aTitle ) throw( RuntimeException )
95 {
96     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
97     MutexGuard aGuard( m_aMutex );
98     m_pFolderPickerImpl->setTitle( aTitle );
99 }
100 
101 //-----------------------------------------------------------------------------------------
102 //
103 //-----------------------------------------------------------------------------------------
104 
105 void SAL_CALL CFolderPicker::setDisplayDirectory( const OUString& aDirectory )
106     throw( IllegalArgumentException, RuntimeException )
107 {
108     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
109     MutexGuard aGuard( m_aMutex );
110     m_pFolderPickerImpl->setDisplayDirectory( aDirectory );
111 }
112 
113 //-----------------------------------------------------------------------------------------
114 //
115 //-----------------------------------------------------------------------------------------
116 
117 OUString SAL_CALL CFolderPicker::getDisplayDirectory( )
118     throw( RuntimeException )
119 {
120     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
121     MutexGuard aGuard( m_aMutex );
122     return m_pFolderPickerImpl->getDisplayDirectory( );
123 }
124 
125 //-----------------------------------------------------------------------------------------
126 //
127 //-----------------------------------------------------------------------------------------
128 
129 OUString SAL_CALL CFolderPicker::getDirectory( ) throw( RuntimeException )
130 {
131     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
132     MutexGuard aGuard( m_aMutex );
133     return m_pFolderPickerImpl->getDirectory( );
134 }
135 
136 //-----------------------------------------------------------------------------------------
137 //
138 //-----------------------------------------------------------------------------------------
139 
140 void SAL_CALL CFolderPicker::setDescription( const OUString& aDescription ) throw( RuntimeException )
141 {
142     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
143     MutexGuard aGuard( m_aMutex );
144     m_pFolderPickerImpl->setDescription( aDescription );
145 }
146 
147 //-----------------------------------------------------------------------------------------
148 //
149 //-----------------------------------------------------------------------------------------
150 
151 sal_Int16 SAL_CALL CFolderPicker::execute( )
152     throw( RuntimeException )
153 {
154     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
155 
156     // we should not block in this call else
157     // in the case of an event the client can'tgetPImplFromHandle( hWnd )
158     // call another function an we run into a
159     // deadlock !!!!!
160     return m_pFolderPickerImpl->execute( );
161 }
162 
163 // -------------------------------------------------
164 // XServiceInfo
165 // -------------------------------------------------
166 
167 OUString SAL_CALL CFolderPicker::getImplementationName(  )
168     throw( RuntimeException )
169 {
170     return OUString::createFromAscii( FOLDERPICKER_IMPL_NAME );
171 }
172 
173 // -------------------------------------------------
174 //  XServiceInfo
175 // -------------------------------------------------
176 
177 sal_Bool SAL_CALL CFolderPicker::supportsService( const OUString& ServiceName )
178     throw( RuntimeException )
179 {
180     Sequence < OUString > SupportedServicesNames = FolderPicker_getSupportedServiceNames();
181 
182     for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
183         if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
184             return sal_True;
185 
186     return sal_False;
187 }
188 
189 // -------------------------------------------------
190 //  XServiceInfo
191 // -------------------------------------------------
192 
193 Sequence< OUString > SAL_CALL CFolderPicker::getSupportedServiceNames(   )
194     throw( RuntimeException )
195 {
196     return FolderPicker_getSupportedServiceNames();
197 }
198 
199 // -------------------------------------------------
200 //  XCancellable
201 // -------------------------------------------------
202 
203 void SAL_CALL CFolderPicker::cancel( )
204     throw(RuntimeException)
205 {
206     OSL_ASSERT( m_pFolderPickerImpl.get( ) );
207     MutexGuard aGuard( m_aMutex );
208     m_pFolderPickerImpl->cancel( );
209 }
210 
211 //------------------------------------------------
212 // overwrite base class method, which is called
213 // by base class dispose function
214 //------------------------------------------------
215 
216 void SAL_CALL CFolderPicker::disposing()
217 {
218 }
219 
220