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 
31 #ifdef _MSC_VER
32 #pragma warning (disable:4917)
33 #endif
34 
35 #include "VistaFilePicker.hxx"
36 #include "WinFileOpenImpl.hxx"
37 #include "..\misc\WinImplHelper.hxx"
38 #include "shared.hxx"
39 
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
42 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
43 #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
44 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
45 
46 #include <cppuhelper/interfacecontainer.h>
47 #include <comphelper/configurationhelper.hxx>
48 #include <osl/diagnose.h>
49 #include <osl/mutex.hxx>
50 #include <osl/file.hxx>
51 #include <tchar.h>
52 
53 #ifdef _MSC_VER
54 #pragma warning (push, 1)
55 #endif
56 #include <shlobj.h>
57 #ifdef _MSC_VER
58 #pragma warning (pop)
59 #endif
60 
61 //------------------------------------------------------------------------
62 // namespace directives
63 //------------------------------------------------------------------------
64 
65 namespace css = ::com::sun::star;
66 
67 namespace fpicker{
68 namespace win32{
69 namespace vista{
70 
71 //------------------------------------------------------------------------
72 // defines
73 //------------------------------------------------------------------------
74 
75 #define FILE_PICKER_DLL_NAME  TEXT("fps.dll")
76 
77 //------------------------------------------------------------------------
78 // helper functions
79 //------------------------------------------------------------------------
80 
81 namespace
82 {
83     // controlling event notifications
84     const bool STARTUP_SUSPENDED = true;
85     const bool STARTUP_ALIVE     = false;
86 
VistaFilePicker_getSupportedServiceNames()87 	css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker_getSupportedServiceNames()
88 	{
89 		css::uno::Sequence< ::rtl::OUString > aRet(2);
90         aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.FilePicker");
91 		aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.SystemFilePicker");
92 		return aRet;
93 	}
94 }
95 
96 //-----------------------------------------------------------------------------------------
97 #define ENABLE_LOGGING
98 
99 #define LOGFILE_VISTA "c:\\temp\\vistafiledialog.log"
100 
101 #ifdef ENABLE_LOGGING
102 
103     #define LOG_FILE(PARAM_MESSAGE)                                 \
104         {                                                           \
105             FILE* pFile = fopen(LOGFILE_VISTA, "a");                \
106             fprintf(pFile, PARAM_MESSAGE);                          \
107             fclose(pFile);                                          \
108         }
109 
110     #define LOG_FILE_1_PARAM(PARAM_MESSAGE, PARAM_1)                \
111         {                                                           \
112             FILE* pFile = fopen(LOGFILE_VISTA, "a");                \
113             fprintf(pFile, PARAM_MESSAGE, PARAM_1);                 \
114             fclose(pFile);                                          \
115         }
116 
117     #define LOG_FILE_2_PARAM(PARAM_MESSAGE, PARAM_1, PARAM_2)       \
118         {                                                           \
119             FILE* pFile = fopen(LOGFILE_VISTA, "a");                \
120             fprintf(pFile, PARAM_MESSAGE, PARAM_1, PARAM_2);        \
121             fclose(pFile);                                          \
122         }
123 
124 #else
125 
126     #define LOG_FILE(PARAM_MESSAGE)
127     #define LOG_FILE_1_PARAM(PARAM_MESSAGE, PARAM_1)
128     #define LOG_FILE_2_PARAM(PARAM_MESSAGE, PARAM_1, PARAM_2)
129 
130 #endif
131 
132 //-----------------------------------------------------------------------------------------
133 #define VISTAFILEDIALOG_CHECKED_COMCALL(PARAM_CODE, PARAM_LOGMESSAGE, PARAM_ERRORMESSAGE)                                   \
134     {                                                                                                                       \
135         HRESULT aResult;                                                                                                    \
136         VISTAFILEDIALOG_CHECKED_COMCALL_WITH_RETURN(aResult, PARAM_CODE, PARAM_LOGMESSAGE, PARAM_ERRORMESSAGE)              \
137     }
138 
139 //-----------------------------------------------------------------------------------------
140 #define VISTAFILEDIALOG_CHECKED_COMCALL_WITH_RETURN(RETURN_HR, PARAM_CODE, PARAM_LOGMESSAGE, PARAM_ERRORMESSAGE)            \
141     {                                                                                                                       \
142         LOG_FILE(PARAM_LOGMESSAGE)                                                                                          \
143         RETURN_HR = PARAM_CODE;                                                                                             \
144         if ( FAILED(RETURN_HR) )                                                                                            \
145         {                                                                                                                   \
146             LOG_FILE_1_PARAM("will throw exception for checked COM call:\n%s", PARAM_ERRORMESSAGE)                          \
147             throw css::uno::RuntimeException(                                                                               \
148                 ::rtl::OUString::createFromAscii(PARAM_ERRORMESSAGE),                                                       \
149                 css::uno::Reference< css::ui::dialogs::XFilePicker >());                                                    \
150         }                                                                                                                   \
151     }
152 
153 
154 
155 //-----------------------------------------------------------------------------------------
VistaFilePicker(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)156 VistaFilePicker::VistaFilePicker(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
157     : TVistaFilePickerBase  (m_aMutex                 )
158     , m_xSMGR               (xSMGR                    )
159     , m_rDialog             (new VistaFilePickerImpl())
160     , m_aAsyncExecute       (m_rDialog                )
161     , m_nFilePickerThreadId (0                        )
162 	, m_bInitialized		(false					  )
163 {
164 }
165 
166 //-----------------------------------------------------------------------------------------
~VistaFilePicker()167 VistaFilePicker::~VistaFilePicker()
168 {
169 }
170 
171 //------------------------------------------------------------------------------------
addFilePickerListener(const css::uno::Reference<css::ui::dialogs::XFilePickerListener> & xListener)172 void SAL_CALL VistaFilePicker::addFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener)
173 	throw(css::uno::RuntimeException)
174 {
175     RequestRef rRequest(new Request());
176     rRequest->setRequest (VistaFilePickerImpl::E_ADD_PICKER_LISTENER);
177     rRequest->setArgument(PROP_PICKER_LISTENER, xListener);
178 
179     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
180 }
181 
182 //-----------------------------------------------------------------------------------------
removeFilePickerListener(const css::uno::Reference<css::ui::dialogs::XFilePickerListener> & xListener)183 void SAL_CALL VistaFilePicker::removeFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener )
184 	throw(css::uno::RuntimeException)
185 {
186     RequestRef rRequest(new Request());
187     rRequest->setRequest (VistaFilePickerImpl::E_REMOVE_PICKER_LISTENER);
188     rRequest->setArgument(PROP_PICKER_LISTENER, xListener);
189 
190     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
191 }
192 
193 // -------------------------------------------------
disposing(const css::lang::EventObject &)194 void SAL_CALL VistaFilePicker::disposing(const css::lang::EventObject& /*aEvent*/)
195     throw(css::uno::RuntimeException)
196 {
197 }
198 
199 //------------------------------------------------------------------------------------
setMultiSelectionMode(::sal_Bool bMode)200 void SAL_CALL VistaFilePicker::setMultiSelectionMode(::sal_Bool bMode)
201     throw(css::uno::RuntimeException)
202 {
203     RequestRef rRequest(new Request());
204     rRequest->setRequest (VistaFilePickerImpl::E_SET_MULTISELECTION_MODE);
205     rRequest->setArgument(PROP_MULTISELECTION_MODE, bMode);
206 
207     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
208 }
209 
210 //-----------------------------------------------------------------------------------------
setTitle(const::rtl::OUString & sTitle)211 void SAL_CALL VistaFilePicker::setTitle(const ::rtl::OUString& sTitle)
212     throw(css::uno::RuntimeException)
213 {
214     RequestRef rRequest(new Request());
215     rRequest->setRequest (VistaFilePickerImpl::E_SET_TITLE);
216     rRequest->setArgument(PROP_TITLE, sTitle);
217 
218     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
219 }
220 
221 //-----------------------------------------------------------------------------------------
appendFilter(const::rtl::OUString & sTitle,const::rtl::OUString & sFilter)222 void SAL_CALL VistaFilePicker::appendFilter(const ::rtl::OUString& sTitle ,
223                                             const ::rtl::OUString& sFilter)
224 	throw(css::lang::IllegalArgumentException,
225           css::uno::RuntimeException         )
226 {
227     RequestRef rRequest(new Request());
228     rRequest->setRequest (VistaFilePickerImpl::E_APPEND_FILTER);
229     rRequest->setArgument(PROP_FILTER_TITLE, sTitle );
230     rRequest->setArgument(PROP_FILTER_VALUE, sFilter);
231 
232     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
233 }
234 
235 //-----------------------------------------------------------------------------------------
setCurrentFilter(const::rtl::OUString & sTitle)236 void SAL_CALL VistaFilePicker::setCurrentFilter(const ::rtl::OUString& sTitle)
237 	throw(css::lang::IllegalArgumentException,
238           css::uno::RuntimeException         )
239 {
240     RequestRef rRequest(new Request());
241     rRequest->setRequest (VistaFilePickerImpl::E_SET_CURRENT_FILTER);
242     rRequest->setArgument(PROP_FILTER_TITLE, sTitle);
243 
244     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
245 }
246 
247 //-----------------------------------------------------------------------------------------
getCurrentFilter()248 ::rtl::OUString SAL_CALL VistaFilePicker::getCurrentFilter()
249     throw(css::uno::RuntimeException)
250 {
251     RequestRef rRequest(new Request());
252     rRequest->setRequest (VistaFilePickerImpl::E_GET_CURRENT_FILTER);
253 
254     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED);
255 
256     const  ::rtl::OUString sTitle = rRequest->getArgumentOrDefault(PROP_FILTER_TITLE, ::rtl::OUString());
257     return sTitle;
258 }
259 
260 //-----------------------------------------------------------------------------------------
appendFilterGroup(const::rtl::OUString &,const css::uno::Sequence<css::beans::StringPair> & rFilters)261 void SAL_CALL VistaFilePicker::appendFilterGroup(const ::rtl::OUString&                              /*sGroupTitle*/,
262                                                  const css::uno::Sequence< css::beans::StringPair >& rFilters   )
263 	throw (css::lang::IllegalArgumentException,
264            css::uno::RuntimeException         )
265 {
266     RequestRef rRequest(new Request());
267     rRequest->setRequest (VistaFilePickerImpl::E_APPEND_FILTERGROUP);
268     rRequest->setArgument(PROP_FILTER_GROUP, rFilters);
269 
270     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
271 }
272 
273 //-----------------------------------------------------------------------------------------
setDefaultName(const::rtl::OUString & sName)274 void SAL_CALL VistaFilePicker::setDefaultName(const ::rtl::OUString& sName )
275     throw(css::uno::RuntimeException)
276 {
277     RequestRef rRequest(new Request());
278     rRequest->setRequest (VistaFilePickerImpl::E_SET_DEFAULT_NAME);
279     rRequest->setArgument(PROP_FILENAME, sName);
280 
281     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
282 }
283 
284 //-----------------------------------------------------------------------------------------
setDisplayDirectory(const::rtl::OUString & sDirectory)285 void SAL_CALL VistaFilePicker::setDisplayDirectory(const ::rtl::OUString& sDirectory)
286 	throw (css::lang::IllegalArgumentException,
287            css::uno::RuntimeException         )
288 {
289     const ::rtl::OUString aPackage( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/"));
290     const ::rtl::OUString aRelPath( RTL_CONSTASCII_USTRINGPARAM("Path/Info"));
291     const ::rtl::OUString aKey( RTL_CONSTASCII_USTRINGPARAM("WorkPathChanged"));
292 
293     css::uno::Any aValue = ::comphelper::ConfigurationHelper::readDirectKey(
294         m_xSMGR, aPackage, aRelPath, aKey, ::comphelper::ConfigurationHelper::E_READONLY);
295 
296     bool bChanged(false);
297     if (( aValue >>= bChanged ) && bChanged )
298     {
299         ::comphelper::ConfigurationHelper::writeDirectKey(
300             m_xSMGR, aPackage, aRelPath, aKey, css::uno::makeAny(false), ::comphelper::ConfigurationHelper::E_STANDARD);
301     }
302 
303     RequestRef rRequest(new Request());
304     rRequest->setRequest (VistaFilePickerImpl::E_SET_DIRECTORY);
305     rRequest->setArgument(PROP_DIRECTORY, sDirectory);
306     rRequest->setArgument(PROP_FORCE, bChanged);
307 
308     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
309 }
310 
311 //-----------------------------------------------------------------------------------------
getDisplayDirectory()312 ::rtl::OUString SAL_CALL VistaFilePicker::getDisplayDirectory()
313     throw(css::uno::RuntimeException)
314 {
315 	RequestRef rRequest(new Request());
316     rRequest->setRequest (VistaFilePickerImpl::E_GET_DIRECTORY);
317 	m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
318 	const ::rtl::OUString sDirectory = rRequest->getArgumentOrDefault(PROP_DIRECTORY, ::rtl::OUString());
319 
320     return sDirectory;
321 }
322 
323 //-----------------------------------------------------------------------------------------
324 // @deprecated can't be supported any longer ... see IDL description for further details
getFiles()325 css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker::getFiles()
326     throw(css::uno::RuntimeException)
327 {
328     RequestRef rRequest(new Request());
329     rRequest->setRequest (VistaFilePickerImpl::E_GET_SELECTED_FILES);
330 
331     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED);
332 
333     const  css::uno::Sequence< ::rtl::OUString > lFiles = rRequest->getArgumentOrDefault(PROP_SELECTED_FILES, css::uno::Sequence< ::rtl::OUString >());
334     m_lLastFiles = lFiles;
335     return lFiles;
336 }
337 
338 //-----------------------------------------------------------------------------------------
getSelectedFiles()339 css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker::getSelectedFiles()
340     throw(css::uno::RuntimeException)
341 {
342     RequestRef rRequest(new Request());
343     rRequest->setRequest (VistaFilePickerImpl::E_GET_SELECTED_FILES);
344 
345     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED);
346 
347     const  css::uno::Sequence< ::rtl::OUString > lFiles = rRequest->getArgumentOrDefault(PROP_SELECTED_FILES, css::uno::Sequence< ::rtl::OUString >());
348     m_lLastFiles = lFiles;
349     return lFiles;
350 }
351 
352 //-----------------------------------------------------------------------------------------
execute()353 ::sal_Int16 SAL_CALL VistaFilePicker::execute()
354     throw(css::uno::RuntimeException)
355 {
356 	bool bInitialized(false);
357 	{
358 		osl::MutexGuard aGuard(m_aMutex);
359 		bInitialized = m_bInitialized;
360 	}
361 
362 	if ( !bInitialized )
363 	{
364 		sal_Int16 nTemplateDescription = css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE;
365 		css::uno::Sequence < css::uno::Any > aInitArguments(1);
366 		aInitArguments[0] <<= nTemplateDescription;
367 		initialize(aInitArguments);
368 	}
369 
370     RequestRef rRequest(new Request());
371     rRequest->setRequest (VistaFilePickerImpl::E_SHOW_DIALOG_MODAL);
372 
373 	// if we want to show a modal window, the calling thread needs to process messages
374 	m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::PROCESS_MESSAGES);
375 
376     const ::sal_Bool bOK          = rRequest->getArgumentOrDefault(PROP_DIALOG_SHOW_RESULT, (::sal_Bool)sal_False                  );
377                      m_lLastFiles = rRequest->getArgumentOrDefault(PROP_SELECTED_FILES    , css::uno::Sequence< ::rtl::OUString >());
378 
379     ::sal_Int16 nResult = css::ui::dialogs::ExecutableDialogResults::CANCEL;
380     if (bOK)
381         nResult = css::ui::dialogs::ExecutableDialogResults::OK;
382     return nResult;
383 }
384 
385 //------------------------------------------------------------------------------------
386 // XFilePicker functions
387 //------------------------------------------------------------------------------------
388 
setValue(::sal_Int16 nControlId,::sal_Int16 nControlAction,const css::uno::Any & aValue)389 void SAL_CALL VistaFilePicker::setValue(      ::sal_Int16    nControlId    ,
390                                               ::sal_Int16    nControlAction,
391                                         const css::uno::Any& aValue        )
392 	throw(css::uno::RuntimeException)
393 {
394     RequestRef rRequest(new Request());
395     rRequest->setRequest (VistaFilePickerImpl::E_SET_CONTROL_VALUE);
396     rRequest->setArgument(PROP_CONTROL_ID    , nControlId    );
397     rRequest->setArgument(PROP_CONTROL_ACTION, nControlAction);
398     rRequest->setArgument(PROP_CONTROL_VALUE , aValue        );
399 
400     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
401 }
402 
403 //-----------------------------------------------------------------------------------------
404 //
405 //-----------------------------------------------------------------------------------------
406 
getValue(::sal_Int16 nControlId,::sal_Int16 nControlAction)407 css::uno::Any SAL_CALL VistaFilePicker::getValue(::sal_Int16 nControlId    ,
408                                                  ::sal_Int16 nControlAction)
409 	throw(css::uno::RuntimeException)
410 {
411     RequestRef rRequest(new Request());
412     rRequest->setRequest (VistaFilePickerImpl::E_GET_CONTROL_VALUE);
413     rRequest->setArgument(PROP_CONTROL_ID    , nControlId    );
414     rRequest->setArgument(PROP_CONTROL_ACTION, nControlAction);
415 
416     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED);
417     const css::uno::Any aValue = rRequest->getArgumentOrDefault(PROP_CONTROL_VALUE, css::uno::Any());
418     return aValue;
419 }
420 
421 //-----------------------------------------------------------------------------------------
422 //
423 //-----------------------------------------------------------------------------------------
424 
enableControl(::sal_Int16 nControlId,::sal_Bool bEnable)425 void SAL_CALL VistaFilePicker::enableControl(::sal_Int16 nControlId,
426                                              ::sal_Bool  bEnable   )
427     throw(css::uno::RuntimeException)
428 {
429     RequestRef rRequest(new Request());
430     rRequest->setRequest (VistaFilePickerImpl::E_ENABLE_CONTROL);
431     rRequest->setArgument(PROP_CONTROL_ID    , nControlId);
432     rRequest->setArgument(PROP_CONTROL_ENABLE, bEnable   );
433 
434     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
435 }
436 
437 //-----------------------------------------------------------------------------------------
438 //
439 //-----------------------------------------------------------------------------------------
440 
setLabel(::sal_Int16 nControlId,const::rtl::OUString & sLabel)441 void SAL_CALL VistaFilePicker::setLabel(      ::sal_Int16      nControlId,
442                                          const ::rtl::OUString& sLabel    )
443 	throw (css::uno::RuntimeException)
444 {
445     RequestRef rRequest(new Request());
446     rRequest->setRequest (VistaFilePickerImpl::E_SET_CONTROL_LABEL);
447     rRequest->setArgument(PROP_CONTROL_ID   , nControlId);
448     rRequest->setArgument(PROP_CONTROL_LABEL, sLabel    );
449 
450     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
451 }
452 
453 //-----------------------------------------------------------------------------------------
454 //
455 //-----------------------------------------------------------------------------------------
456 
getLabel(::sal_Int16 nControlId)457 ::rtl::OUString SAL_CALL VistaFilePicker::getLabel(::sal_Int16 nControlId)
458 	throw (css::uno::RuntimeException)
459 {
460     RequestRef rRequest(new Request());
461     rRequest->setRequest (VistaFilePickerImpl::E_GET_CONTROL_LABEL);
462     rRequest->setArgument(PROP_CONTROL_ID, nControlId);
463 
464     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::BLOCKED);
465     const ::rtl::OUString sLabel = rRequest->getArgumentOrDefault(PROP_CONTROL_LABEL, ::rtl::OUString());
466     return sLabel;
467 }
468 
469 //------------------------------------------------------------------------------------
470 //
471 //------------------------------------------------------------------------------------
472 
getSupportedImageFormats()473 css::uno::Sequence< ::sal_Int16 > SAL_CALL VistaFilePicker::getSupportedImageFormats()
474     throw (css::uno::RuntimeException)
475 {
476     return css::uno::Sequence< sal_Int16 >();
477 }
478 
479 //------------------------------------------------------------------------------------
480 //
481 //------------------------------------------------------------------------------------
482 
getTargetColorDepth()483 sal_Int32 SAL_CALL VistaFilePicker::getTargetColorDepth()
484     throw (css::uno::RuntimeException)
485 {
486     return 0;
487 }
488 
489 //------------------------------------------------------------------------------------
490 //
491 //------------------------------------------------------------------------------------
492 
getAvailableWidth()493 sal_Int32 SAL_CALL VistaFilePicker::getAvailableWidth()
494     throw (css::uno::RuntimeException)
495 {
496     return 0;
497 }
498 
499 //------------------------------------------------------------------------------------
500 //
501 //------------------------------------------------------------------------------------
502 
getAvailableHeight()503 sal_Int32 SAL_CALL VistaFilePicker::getAvailableHeight()
504     throw (css::uno::RuntimeException)
505 {
506     return 0;
507 }
508 
509 //------------------------------------------------------------------------------------
510 //
511 //------------------------------------------------------------------------------------
512 
setImage(sal_Int16,const css::uno::Any &)513 void SAL_CALL VistaFilePicker::setImage(      sal_Int16      /*nImageFormat*/,
514                                          const css::uno::Any& /*aImage      */)
515 	throw (css::lang::IllegalArgumentException,
516            css::uno::RuntimeException         )
517 {
518 }
519 
520 //------------------------------------------------------------------------------------
521 //
522 //------------------------------------------------------------------------------------
523 
setShowState(sal_Bool)524 sal_Bool SAL_CALL VistaFilePicker::setShowState(sal_Bool /*bShowState*/)
525     throw (css::uno::RuntimeException)
526 {
527     return sal_False;
528 }
529 
530 //------------------------------------------------------------------------------------
531 //
532 //------------------------------------------------------------------------------------
533 
getShowState()534 sal_Bool SAL_CALL VistaFilePicker::getShowState()
535     throw (css::uno::RuntimeException)
536 {
537     return sal_False;
538 }
539 
540 //------------------------------------------------------------------------------------
541 //
542 //------------------------------------------------------------------------------------
543 
initialize(const css::uno::Sequence<css::uno::Any> & lArguments)544 void SAL_CALL VistaFilePicker::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
545 	throw(css::uno::Exception       ,
546           css::uno::RuntimeException)
547 {
548     /*
549     // called twice ?
550     if (m_pDlg)
551 		throw css::uno::Exception(
552                 ::rtl::OUString::createFromAscii( "XInitialization::initialize() called twice." ),
553                 static_cast< css::ui::dialogs::XFilePicker* >( this ));
554     */
555 
556     if (lArguments.getLength() < 1)
557 		throw css::lang::IllegalArgumentException(
558                 ::rtl::OUString::createFromAscii( "XInitialization::initialize() called without arguments." ),
559                 static_cast< css::ui::dialogs::XFilePicker2* >( this ),
560                 1);
561 
562     sal_Int32         nTemplate = -1;
563     lArguments[0] >>= nTemplate;
564 
565     ::sal_Bool  bFileOpenDialog = sal_True;
566     ::sal_Int32 nFeatures       = 0;
567 
568     switch(nTemplate)
569     {
570         case css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE :
571         {
572             bFileOpenDialog = sal_True;
573         }
574         break;
575 
576         case css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE :
577         {
578             bFileOpenDialog = sal_False;
579         }
580         break;
581 
582         case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD :
583         {
584             bFileOpenDialog  = sal_False;
585             nFeatures        |= FEATURE_AUTOEXTENSION;
586             nFeatures        |= FEATURE_PASSWORD;
587         }
588         break;
589 
590         case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS :
591         {
592             bFileOpenDialog = sal_False;
593             nFeatures        |= FEATURE_AUTOEXTENSION;
594             nFeatures        |= FEATURE_PASSWORD;
595             nFeatures        |= FEATURE_FILTEROPTIONS;
596         }
597         break;
598 
599         case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION :
600         {
601             bFileOpenDialog  = sal_False;
602             nFeatures        |= FEATURE_AUTOEXTENSION;
603             nFeatures        |= FEATURE_SELECTION;
604         }
605         break;
606 
607         case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE :
608         {
609             bFileOpenDialog  = sal_False;
610             nFeatures        |= FEATURE_AUTOEXTENSION;
611             nFeatures        |= FEATURE_TEMPLATE;
612         }
613         break;
614 
615         case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE :
616         {
617             bFileOpenDialog  = sal_True;
618             nFeatures        |= FEATURE_LINK;
619             nFeatures        |= FEATURE_PREVIEW;
620             nFeatures        |= FEATURE_IMAGETEMPLATE;
621         }
622         break;
623 
624         case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY :
625         {
626             bFileOpenDialog  = sal_True;
627             nFeatures        |= FEATURE_PLAY;
628         }
629         break;
630 
631         case css::ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION :
632         {
633             bFileOpenDialog  = sal_True;
634             nFeatures        |= FEATURE_READONLY;
635             nFeatures        |= FEATURE_VERSION;
636         }
637         break;
638 
639         case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW :
640         {
641             bFileOpenDialog  = sal_True;
642             nFeatures        |= FEATURE_LINK;
643             nFeatures        |= FEATURE_PREVIEW;
644         }
645         break;
646 
647         case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION :
648         {
649             bFileOpenDialog  = sal_False;
650             nFeatures        |= FEATURE_AUTOEXTENSION;
651         }
652         break;
653     }
654 
655     RequestRef rRequest(new Request());
656     if (bFileOpenDialog)
657         rRequest->setRequest (VistaFilePickerImpl::E_CREATE_OPEN_DIALOG);
658     else
659         rRequest->setRequest (VistaFilePickerImpl::E_CREATE_SAVE_DIALOG);
660     rRequest->setArgument(PROP_FEATURES, nFeatures);
661 	rRequest->setArgument(PROP_TEMPLATE_DESCR, nTemplate);
662     if ( ! m_aAsyncExecute.isRunning())
663         m_aAsyncExecute.create();
664     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
665 
666 	{
667 		osl::MutexGuard aGuard(m_aMutex);
668 		m_bInitialized = true;
669 	}
670 }
671 
672 //------------------------------------------------------------------------------------
673 //
674 //------------------------------------------------------------------------------------
675 
cancel()676 void SAL_CALL VistaFilePicker::cancel()
677 	throw(css::uno::RuntimeException)
678 {
679 }
680 
681 // -------------------------------------------------
682 // XServiceInfo
683 // -------------------------------------------------
684 
getImplementationName()685 ::rtl::OUString SAL_CALL VistaFilePicker::getImplementationName()
686 	throw(css::uno::RuntimeException)
687 {
688 	return ::rtl::OUString::createFromAscii("com.sun.star.comp.fpicker.VistaFileDialog");
689 }
690 
691 // -------------------------------------------------
692 //	XServiceInfo
693 // -------------------------------------------------
694 
supportsService(const::rtl::OUString & sServiceName)695 sal_Bool SAL_CALL VistaFilePicker::supportsService(const ::rtl::OUString& sServiceName)
696 	throw(css::uno::RuntimeException )
697 {
698 	css::uno::Sequence< ::rtl::OUString > lSupportedServicesNames = VistaFilePicker_getSupportedServiceNames();
699 
700 	for (sal_Int32 n = lSupportedServicesNames.getLength(); n--;)
701 		if (lSupportedServicesNames[n].compareTo(sServiceName) == 0)
702 			return sal_True;
703 
704 	return sal_False;
705 }
706 
707 // -------------------------------------------------
708 //	XServiceInfo
709 // -------------------------------------------------
710 
getSupportedServiceNames()711 css::uno::Sequence< ::rtl::OUString > SAL_CALL VistaFilePicker::getSupportedServiceNames()
712 	throw(css::uno::RuntimeException)
713 {
714 	return VistaFilePicker_getSupportedServiceNames();
715 }
716 
717 } // namespace vista
718 } // namespace win32
719 } // namespace fpicker
720