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 
35 #include <tchar.h>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <cppuhelper/interfacecontainer.h>
38 #include <osl/diagnose.h>
39 
40 #ifndef _FILEPICKER_HXX_
41 #include "filepicker.hxx"
42 #endif
43 #include "WinFileOpenImpl.hxx"
44 
45 #include "FPServiceInfo.hxx"
46 #include "..\misc\WinImplHelper.hxx"
47 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
48 #include "filepickereventnotification.hxx"
49 
50 #include <comphelper/sequenceasvector.hxx>
51 
52 //------------------------------------------------------------------------
53 // namespace directives
54 //------------------------------------------------------------------------
55 
56 using namespace com::sun::star;
57 
58 using namespace ::com::sun::star::ui::dialogs;
59 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
60 
61 //------------------------------------------------------------------------
62 // defines
63 //------------------------------------------------------------------------
64 
65 #define FILE_PICKER_DLL_NAME  TEXT("fps.dll")
66 
67 //------------------------------------------------------------------------
68 // helper functions
69 //------------------------------------------------------------------------
70 
71 namespace
72 {
73     // controling event notifications
74     const bool STARTUP_SUSPENDED = true;
75     const bool STARTUP_ALIVE     = false;
76 
77 	uno::Sequence<rtl::OUString> SAL_CALL FilePicker_getSupportedServiceNames()
78 	{
79 		uno::Sequence<rtl::OUString> aRet(2);
80         aRet[0] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.FilePicker");
81 		aRet[1] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.SystemFilePicker");
82 		return aRet;
83 	}
84 }
85 
86 //-----------------------------------------------------------------------------------------
87 //
88 //-----------------------------------------------------------------------------------------
89 
90 CFilePicker::CFilePicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr) :
91 	cppu::WeakComponentImplHelper10<
92 		XFilterManager,
93         XFilterGroupManager,
94         XFilePickerControlAccess,
95 		XFilePickerNotifier,
96         XFilePreview,
97         XFilePicker2,
98 		lang::XInitialization,
99 		util::XCancellable,
100 		lang::XEventListener,
101 		lang::XServiceInfo>(m_rbHelperMtx),
102 		m_xServiceMgr(xServiceMgr),
103 		m_aAsyncEventNotifier(rBHelper)
104 {
105     HINSTANCE hInstance = GetModuleHandle(FILE_PICKER_DLL_NAME);
106 	OSL_POSTCOND( hInstance, "The name of the service dll must have changed" );
107 
108 	// create a default FileOpen dialog without any additional ui elements
109 	m_pImpl = std::auto_ptr< CWinFileOpenImpl >(
110         new CWinFileOpenImpl(
111             this,
112             true,
113 			0,
114 			0,
115 			hInstance ) );
116 }
117 
118 //------------------------------------------------------------------------------------
119 // XFPEventListenerManager
120 //------------------------------------------------------------------------------------
121 
122 void SAL_CALL CFilePicker::addFilePickerListener(const uno::Reference<XFilePickerListener>& xListener)
123 	throw(uno::RuntimeException)
124 {
125 	if ( rBHelper.bDisposed )
126 		throw lang::DisposedException(
127 			rtl::OUString::createFromAscii( "object is already disposed" ),
128 			static_cast< XFilePicker2* >( this ) );
129 
130 	if ( !rBHelper.bInDispose && !rBHelper.bDisposed )
131 		rBHelper.aLC.addInterface( getCppuType( &xListener ), xListener );
132 }
133 
134 //-----------------------------------------------------------------------------------------
135 //
136 //-----------------------------------------------------------------------------------------
137 
138 void SAL_CALL CFilePicker::removeFilePickerListener(const uno::Reference<XFilePickerListener>& xListener )
139 	throw(uno::RuntimeException)
140 {
141 	if ( rBHelper.bDisposed )
142 		throw lang::DisposedException(
143 			rtl::OUString::createFromAscii( "object is already disposed" ),
144 			static_cast< XFilePicker2* >( this ) );
145 
146 	rBHelper.aLC.removeInterface( getCppuType( &xListener ), xListener );
147 }
148 
149 // -------------------------------------------------
150 // XEventListener
151 // -------------------------------------------------
152 
153 void SAL_CALL CFilePicker::disposing(const lang::EventObject& aEvent) throw(uno::RuntimeException)
154 {
155 	uno::Reference<XFilePickerListener> xFilePickerListener(aEvent.Source, ::com::sun::star::uno::UNO_QUERY);
156 
157 	if (xFilePickerListener.is())
158 		removeFilePickerListener(xFilePickerListener);
159 }
160 
161 //-----------------------------------------------------------------------------------------
162 //
163 //-----------------------------------------------------------------------------------------
164 
165 void SAL_CALL CFilePicker::fileSelectionChanged(FilePickerEvent aEvent)
166 {
167 	aEvent.Source = uno::Reference<uno::XInterface>(static_cast<XFilePickerNotifier*>(this));
168 	m_aAsyncEventNotifier.notifyEvent(
169 		new CFilePickerParamEventNotification(&XFilePickerListener::fileSelectionChanged,aEvent));
170 }
171 
172 //-----------------------------------------------------------------------------------------
173 //
174 //-----------------------------------------------------------------------------------------
175 
176 void SAL_CALL CFilePicker::directoryChanged(FilePickerEvent aEvent)
177 {
178 	aEvent.Source = uno::Reference<uno::XInterface>(static_cast<XFilePickerNotifier*>(this));
179 	m_aAsyncEventNotifier.notifyEvent(
180 		new CFilePickerParamEventNotification(&XFilePickerListener::directoryChanged,aEvent));
181 }
182 
183 //-----------------------------------------------------------------------------------------
184 //
185 //-----------------------------------------------------------------------------------------
186 
187 void SAL_CALL CFilePicker::controlStateChanged(FilePickerEvent aEvent)
188 {
189 	aEvent.Source = uno::Reference<uno::XInterface>(static_cast<XFilePickerNotifier*>(this));
190 	m_aAsyncEventNotifier.notifyEvent(
191 		new CFilePickerParamEventNotification(&XFilePickerListener::controlStateChanged,aEvent));
192 }
193 
194 //-----------------------------------------------------------------------------------------
195 //
196 //-----------------------------------------------------------------------------------------
197 
198 void SAL_CALL CFilePicker::dialogSizeChanged()
199 {
200 	m_aAsyncEventNotifier.notifyEvent(
201 		new CFilePickerEventNotification(&XFilePickerListener::dialogSizeChanged));
202 }
203 
204 //-----------------------------------------------------------------------------------------
205 // If there are more then one listener the return value of the last one wins
206 //-----------------------------------------------------------------------------------------
207 
208 rtl::OUString SAL_CALL CFilePicker::helpRequested(FilePickerEvent aEvent) const
209 {
210     rtl::OUString aHelpText;
211 
212 	::cppu::OInterfaceContainerHelper* pICHelper =
213 		rBHelper.getContainer( getCppuType((uno::Reference<XFilePickerListener>*)0));
214 
215 	if (pICHelper)
216 	{
217 		::cppu::OInterfaceIteratorHelper iter(*pICHelper);
218 
219 		while(iter.hasMoreElements())
220 		{
221 			try
222 			{
223 				/*
224                   if there are multiple listeners responding
225                   to this notification the next response
226                   overwrittes  the one before if it is not empty
227                 */
228 
229                 rtl::OUString temp;
230 
231 				uno::Reference<XFilePickerListener> xFPListener(iter.next(), uno::UNO_QUERY);
232 				if (xFPListener.is())
233                 {
234 					temp = xFPListener->helpRequested(aEvent);
235                     if (temp.getLength())
236 						aHelpText = temp;
237                 }
238 
239 			}
240 			catch(uno::RuntimeException&)
241 			{
242 				OSL_ENSURE( false, "RuntimeException during event dispatching" );
243 			}
244 		}
245 	}
246 
247     return aHelpText;
248 }
249 
250 //-------------------------------------
251 //
252 //-------------------------------------
253 
254 bool CFilePicker::startupEventNotification(bool bStartupSuspended)
255 {
256     return m_aAsyncEventNotifier.startup(bStartupSuspended);
257 }
258 
259 //-------------------------------------
260 //
261 //-------------------------------------
262 
263 void CFilePicker::shutdownEventNotification()
264 {
265     m_aAsyncEventNotifier.shutdown();
266 }
267 
268 //-------------------------------------
269 //
270 //-------------------------------------
271 
272 void CFilePicker::suspendEventNotification()
273 {
274     m_aAsyncEventNotifier.suspend();
275 }
276 
277 //-------------------------------------
278 //
279 //-------------------------------------
280 
281 void CFilePicker::resumeEventNotification()
282 {
283     m_aAsyncEventNotifier.resume();
284 }
285 
286 //------------------------------------------------------------------------------------
287 // XFilePicker functions
288 //------------------------------------------------------------------------------------
289 
290 void SAL_CALL CFilePicker::setMultiSelectionMode(sal_Bool bMode) throw(uno::RuntimeException)
291 {
292 	OSL_ASSERT(0 != m_pImpl.get());
293 	osl::MutexGuard aGuard(m_aMutex);
294 	m_pImpl->setMultiSelectionMode(bMode);
295 }
296 
297 //-----------------------------------------------------------------------------------------
298 //
299 //-----------------------------------------------------------------------------------------
300 
301 void SAL_CALL CFilePicker::setTitle(const rtl::OUString& aTitle) throw(uno::RuntimeException)
302 {
303 	OSL_ASSERT(0 != m_pImpl.get());
304 	osl::MutexGuard aGuard(m_aMutex);
305 	m_pImpl->setTitle(aTitle);
306 }
307 
308 //-----------------------------------------------------------------------------------------
309 //
310 //-----------------------------------------------------------------------------------------
311 
312 void SAL_CALL CFilePicker::appendFilter(const rtl::OUString& aTitle, const rtl::OUString& aFilter)
313 	throw(lang::IllegalArgumentException, uno::RuntimeException)
314 {
315 	OSL_ASSERT(0 != m_pImpl.get());
316 	osl::MutexGuard aGuard(m_aMutex);
317 	m_pImpl->appendFilter(aTitle, aFilter);
318 }
319 
320 //-----------------------------------------------------------------------------------------
321 //
322 //-----------------------------------------------------------------------------------------
323 
324 void SAL_CALL CFilePicker::setCurrentFilter(const rtl::OUString& aTitle)
325 	throw(lang::IllegalArgumentException, uno::RuntimeException)
326 {
327 	OSL_ASSERT(0 != m_pImpl.get());
328 	osl::MutexGuard aGuard(m_aMutex);
329 	m_pImpl->setCurrentFilter(aTitle);
330 }
331 
332 //-----------------------------------------------------------------------------------------
333 //
334 //-----------------------------------------------------------------------------------------
335 
336 rtl::OUString SAL_CALL CFilePicker::getCurrentFilter() throw(uno::RuntimeException)
337 {
338 	OSL_ASSERT(0 != m_pImpl.get());
339 	osl::MutexGuard aGuard(m_aMutex);
340 	return m_pImpl->getCurrentFilter();
341 }
342 
343 //-----------------------------------------------------------------------------------------
344 //
345 //-----------------------------------------------------------------------------------------
346 
347 void SAL_CALL CFilePicker::appendFilterGroup(const rtl::OUString& sGroupTitle, const uno::Sequence<beans::StringPair>& aFilters)
348 	throw (lang::IllegalArgumentException, uno::RuntimeException)
349 {
350     OSL_ASSERT(0 != m_pImpl.get());
351 	osl::MutexGuard aGuard(m_aMutex);
352 	m_pImpl->appendFilterGroup(sGroupTitle, aFilters);
353 }
354 
355 //-----------------------------------------------------------------------------------------
356 //
357 //-----------------------------------------------------------------------------------------
358 
359 void SAL_CALL CFilePicker::setDefaultName(const rtl::OUString& aName)
360 	throw(uno::RuntimeException)
361 {
362 	OSL_ASSERT(0 != m_pImpl.get());
363 	osl::MutexGuard aGuard(m_aMutex);
364 	m_pImpl->setDefaultName(aName);
365 }
366 
367 //-----------------------------------------------------------------------------------------
368 //
369 //-----------------------------------------------------------------------------------------
370 
371 void SAL_CALL CFilePicker::setDisplayDirectory(const rtl::OUString& aDirectory)
372 	throw(lang::IllegalArgumentException, uno::RuntimeException)
373 {
374 	OSL_ASSERT(0 != m_pImpl.get());
375 	osl::MutexGuard aGuard(m_aMutex);
376 	m_pImpl->setDisplayDirectory(aDirectory);
377 }
378 
379 //-----------------------------------------------------------------------------------------
380 //
381 //-----------------------------------------------------------------------------------------
382 
383 rtl::OUString SAL_CALL CFilePicker::getDisplayDirectory() throw(uno::RuntimeException)
384 {
385 	OSL_ASSERT(0 != m_pImpl.get());
386 	osl::MutexGuard aGuard(m_aMutex);
387 	return m_pImpl->getDisplayDirectory();
388 }
389 
390 //-----------------------------------------------------------------------------------------
391 //
392 //-----------------------------------------------------------------------------------------
393 
394 uno::Sequence<rtl::OUString> SAL_CALL CFilePicker::getFiles() throw(uno::RuntimeException)
395 {
396 	OSL_ASSERT(0 != m_pImpl.get());
397 	osl::MutexGuard aGuard(m_aMutex);
398 	return m_pImpl->getFiles();
399 }
400 
401 //-----------------------------------------------------------------------------------------
402 //
403 //-----------------------------------------------------------------------------------------
404 uno::Sequence< ::rtl::OUString > SAL_CALL CFilePicker::getSelectedFiles() throw (uno::RuntimeException)
405 {
406 	OSL_ASSERT(0 != m_pImpl.get());
407 	osl::MutexGuard aGuard(m_aMutex);
408 
409 	const uno::Sequence< ::rtl::OUString > lSource = m_pImpl->getFiles();
410     const ::sal_Int32                      c       = lSource.getLength();
411     if (c < 2)
412         return lSource;
413 
414 	const ::rtl::OUString                                   sPath  = lSource[0];
415           ::comphelper::SequenceAsVector< ::rtl::OUString > lTarget;
416           ::sal_Int32                                       i      = 1;
417     for (i=1; i<c; ++i)
418 	{
419         const ::rtl::OUString sFile = lSource[i];
420         if (sFile.indexOf ('/') > 0)
421         {
422             // a) file contains own path !
423             lTarget.push_back(sFile);
424         }
425         else
426         {
427             // b) file is relative to given path
428             ::rtl::OUStringBuffer sFull(256);
429 
430             sFull.append     (sPath);
431             sFull.appendAscii("/"  );
432             sFull.append     (sFile);
433 
434             lTarget.push_back(sFull.makeStringAndClear());
435         }
436 	}
437 
438     return lTarget.getAsConstList();
439 }
440 
441 //-----------------------------------------------------------------------------------------
442 //
443 //-----------------------------------------------------------------------------------------
444 
445 sal_Int16 SAL_CALL CFilePicker::execute() throw(uno::RuntimeException)
446 {
447 	OSL_ASSERT(0 != m_pImpl.get());
448 
449 	sal_Int16 ret;
450 
451 	if (startupEventNotification(STARTUP_SUSPENDED))
452 	{
453 		// we should not block in this call else
454 		// in the case of an event the client can't
455 		// call another function an we run into a
456 		// deadlock !!!!!
457 		ret = m_pImpl->execute( );
458 
459 		shutdownEventNotification();
460 	}
461 	else
462 	{
463 		OSL_ENSURE(sal_False, "Could not start event notifier thread!");
464 
465 		throw uno::RuntimeException(
466 			rtl::OUString::createFromAscii("Error executing dialog"),
467 			static_cast<XFilePicker2*>(this));
468 	}
469 
470 	return ret;
471 }
472 
473 //------------------------------------------------------------------------------------
474 // XFilePicker functions
475 //------------------------------------------------------------------------------------
476 
477 void SAL_CALL CFilePicker::setValue(sal_Int16 aControlId, sal_Int16 aControlAction, const uno::Any& aValue)
478 	throw(uno::RuntimeException)
479 {
480 	OSL_ASSERT(0 != m_pImpl.get());
481 
482     osl::MutexGuard aGuard(m_aMutex);
483 	m_pImpl->setValue(aControlId, aControlAction, aValue);
484 }
485 
486 //-----------------------------------------------------------------------------------------
487 //
488 //-----------------------------------------------------------------------------------------
489 
490 uno::Any SAL_CALL CFilePicker::getValue(sal_Int16 aControlId, sal_Int16 aControlAction)
491 	throw(uno::RuntimeException)
492 {
493 	OSL_ASSERT(0 != m_pImpl.get());
494 
495     osl::MutexGuard aGuard(m_aMutex);
496 	return m_pImpl->getValue(aControlId, aControlAction);
497 }
498 
499 //-----------------------------------------------------------------------------------------
500 //
501 //-----------------------------------------------------------------------------------------
502 
503 void SAL_CALL CFilePicker::enableControl(sal_Int16 aControlId, sal_Bool bEnable)
504 throw(uno::RuntimeException)
505 {
506 	OSL_ASSERT( 0 != m_pImpl.get( ) );
507 
508     osl::MutexGuard aGuard( m_aMutex );
509 	m_pImpl->enableControl( aControlId, bEnable );
510 }
511 
512 //-----------------------------------------------------------------------------------------
513 //
514 //-----------------------------------------------------------------------------------------
515 
516 void SAL_CALL CFilePicker::setLabel(sal_Int16 aControlId, const ::rtl::OUString& aLabel)
517 	throw (uno::RuntimeException)
518 {
519     OSL_ASSERT(0 != m_pImpl.get());
520 
521     osl::MutexGuard aGuard(m_aMutex);
522     m_pImpl->setLabel(aControlId, aLabel);
523 }
524 
525 //-----------------------------------------------------------------------------------------
526 //
527 //-----------------------------------------------------------------------------------------
528 
529 rtl::OUString SAL_CALL CFilePicker::getLabel(sal_Int16 aControlId)
530 	throw (uno::RuntimeException)
531 {
532     OSL_ASSERT(0 != m_pImpl.get());
533 
534     osl::MutexGuard aGuard(m_aMutex);
535 	return m_pImpl->getLabel(aControlId);
536 }
537 
538 //------------------------------------------------------------------------------------
539 //
540 //------------------------------------------------------------------------------------
541 
542 uno::Sequence<sal_Int16> SAL_CALL CFilePicker::getSupportedImageFormats() throw (uno::RuntimeException)
543 {
544     OSL_ASSERT(0 != m_pImpl.get());
545 
546     osl::MutexGuard aGuard(m_aMutex);
547     return m_pImpl->getSupportedImageFormats();
548 }
549 
550 //------------------------------------------------------------------------------------
551 //
552 //------------------------------------------------------------------------------------
553 
554 sal_Int32 SAL_CALL CFilePicker::getTargetColorDepth() throw (uno::RuntimeException)
555 {
556     OSL_ASSERT(0 != m_pImpl.get());
557 
558     osl::MutexGuard aGuard(m_aMutex);
559     return m_pImpl->getTargetColorDepth();
560 }
561 
562 //------------------------------------------------------------------------------------
563 //
564 //------------------------------------------------------------------------------------
565 
566 sal_Int32 SAL_CALL CFilePicker::getAvailableWidth() throw (uno::RuntimeException)
567 {
568     OSL_ASSERT(0 != m_pImpl.get());
569 
570     osl::MutexGuard aGuard(m_aMutex);
571     return m_pImpl->getAvailableWidth();
572 }
573 
574 //------------------------------------------------------------------------------------
575 //
576 //------------------------------------------------------------------------------------
577 
578 sal_Int32 SAL_CALL CFilePicker::getAvailableHeight() throw (uno::RuntimeException)
579 {
580     OSL_ASSERT(0 != m_pImpl.get());
581 
582     osl::MutexGuard aGuard(m_aMutex);
583     return m_pImpl->getAvailableHeight();
584 }
585 
586 //------------------------------------------------------------------------------------
587 //
588 //------------------------------------------------------------------------------------
589 
590 void SAL_CALL CFilePicker::setImage(sal_Int16 aImageFormat, const uno::Any& aImage)
591 	throw (lang::IllegalArgumentException, uno::RuntimeException)
592 {
593     OSL_ASSERT(0 != m_pImpl.get());
594 
595     osl::MutexGuard aGuard(m_aMutex);
596     m_pImpl->setImage(aImageFormat, aImage);
597 }
598 
599 //------------------------------------------------------------------------------------
600 //
601 //------------------------------------------------------------------------------------
602 
603 sal_Bool SAL_CALL CFilePicker::setShowState(sal_Bool bShowState) throw (uno::RuntimeException)
604 {
605     OSL_ASSERT(0 != m_pImpl.get());
606 
607     osl::MutexGuard aGuard(m_aMutex);
608     return m_pImpl->setShowState(bShowState);
609 }
610 
611 //------------------------------------------------------------------------------------
612 //
613 //------------------------------------------------------------------------------------
614 
615 sal_Bool SAL_CALL CFilePicker::getShowState() throw (uno::RuntimeException)
616 {
617     OSL_ASSERT(0 != m_pImpl.get());
618 
619     osl::MutexGuard aGuard(m_aMutex);
620     return m_pImpl->getShowState();
621 }
622 
623 //------------------------------------------------------------------------------------
624 //
625 //------------------------------------------------------------------------------------
626 
627 void SAL_CALL CFilePicker::initialize(const uno::Sequence<uno::Any>& aArguments)
628 	throw( uno::Exception, uno::RuntimeException)
629 {
630 	// parameter checking
631 	uno::Any aAny;
632 	if ( 0 == aArguments.getLength( ) )
633 		throw lang::IllegalArgumentException(
634 			rtl::OUString::createFromAscii( "no arguments" ),
635 			static_cast<XFilePicker2*>(this), 1);
636 
637     aAny = aArguments[0];
638 
639     if ( (aAny.getValueType() != ::getCppuType((sal_Int16*)0)) &&
640          (aAny.getValueType() != ::getCppuType((sal_Int8*)0)) )
641 		 throw lang::IllegalArgumentException(
642             rtl::OUString::createFromAscii("invalid argument type"),
643             static_cast<XFilePicker2*>(this), 1);
644 
645 	sal_Int16 templateId = -1;
646 	aAny >>= templateId;
647 
648 	sal_Bool   bFileOpenDialog  = sal_True;
649 	sal_uInt32 winResTemplateId = 0;
650 	sal_Bool   bIsWin2000       = IsWindows2000Platform();
651 
652     switch ( templateId )
653     {
654     case FILEOPEN_SIMPLE:
655         bFileOpenDialog = sal_True;
656         break;
657 
658     case FILESAVE_SIMPLE:
659         bFileOpenDialog = sal_False;
660         break;
661 
662     case FILESAVE_AUTOEXTENSION_PASSWORD:
663         bFileOpenDialog = sal_False;
664         if ( bIsWin2000 )
665             winResTemplateId = TMPL2000_FILESAVE_AUTOEXT_PASSWORD_BOX_ID;
666         else
667             winResTemplateId = TMPL95_FILESAVE_AUTOEXT_PASSWORD_BOX_ID;
668         break;
669 
670     case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
671         bFileOpenDialog = sal_False;
672         if ( bIsWin2000 )
673             winResTemplateId = TMPL2000_AUTOEXT_PASSWORD_FILTEROPTION_BOX;
674         else
675             winResTemplateId = TMPL95_AUTOEXT_PASSWORD_FILTEROPTION_BOX;
676         break;
677 
678     case FILESAVE_AUTOEXTENSION_SELECTION:
679         bFileOpenDialog = sal_False;
680         if ( bIsWin2000 )
681             winResTemplateId = TMPL2000_AUTOEXT_SELECTION_BOX;
682         else
683             winResTemplateId = TMPL95_AUTOEXT_SELECTION_BOX;
684         break;
685 
686     case FILESAVE_AUTOEXTENSION_TEMPLATE:
687         bFileOpenDialog = sal_False;
688         if ( bIsWin2000 )
689             winResTemplateId = TMPL2000_FILEOPEN_AUTOEXT_TEMPLATE_BOX_ID;
690         else
691             winResTemplateId = TMPL95_FILEOPEN_AUTOEXT_TEMPLATE_BOX_ID;
692         break;
693 
694     case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
695         if ( bIsWin2000 )
696             winResTemplateId = TMPL2000_FILEOPEN_LINK_PREVIEW_BOX_ID;
697         else
698             winResTemplateId = TMPL95_FILEOPEN_LINK_PREVIEW_BOX_ID;
699         break;
700 
701     case FILEOPEN_PLAY:
702         if ( bIsWin2000 )
703             winResTemplateId = TMPL2000_PLAY_PUSHBUTTON;
704         else
705             winResTemplateId = TMPL95_PLAY_PUSHBUTTON;
706         break;
707 
708     case FILEOPEN_READONLY_VERSION:
709         if ( bIsWin2000 )
710             winResTemplateId = TMPL2000_FILEOPEN_READONLY_VERSION_BOX_ID;
711         else
712             winResTemplateId = TMPL95_FILEOPEN_READONLY_VERSION_BOX_ID;
713         break;
714 
715     case FILEOPEN_LINK_PREVIEW:
716         if ( bIsWin2000 )
717             winResTemplateId = TMPL2000_FILEOPEN_LINK_PREVIEW_BOX_SIMPLE_ID;
718         else
719             winResTemplateId = TMPL95_FILEOPEN_LINK_PREVIEW_BOX_SIMPLE_ID;
720         break;
721 
722     case FILESAVE_AUTOEXTENSION:
723         bFileOpenDialog = sal_False;
724         if ( bIsWin2000 )
725             winResTemplateId = TMPL2000_FILESAVE_AUTOEXT;
726         else
727             winResTemplateId = TMPL95_FILESAVE_AUTOEXT;
728         break;
729 
730     default:
731         throw lang::IllegalArgumentException(
732 			rtl::OUString::createFromAscii( "Unknown template" ),
733 			static_cast< XFilePicker2* >( this ),
734 			1 );
735     }
736 
737 	HINSTANCE hInstance = GetModuleHandle( FILE_PICKER_DLL_NAME );
738 	OSL_POSTCOND( hInstance, "The name of the service dll must have changed" );
739 
740 	// create a new impl-class here based on the
741 	// given string, if the given string is empty
742 	// we do nothing
743 	m_pImpl = std::auto_ptr< CWinFileOpenImpl >(
744 		new CWinFileOpenImpl(
745 			this,
746 			bFileOpenDialog,
747 			0,
748 			winResTemplateId,
749 			hInstance ) );
750 }
751 
752 //------------------------------------------------------------------------------------
753 //
754 //------------------------------------------------------------------------------------
755 
756 void SAL_CALL CFilePicker::cancel()
757 	throw(uno::RuntimeException)
758 {
759     OSL_ASSERT(m_pImpl.get());
760 
761     osl::MutexGuard aGuard(m_aMutex);
762     m_pImpl->cancel();
763 }
764 
765 // -------------------------------------------------
766 // XServiceInfo
767 // -------------------------------------------------
768 
769 rtl::OUString SAL_CALL CFilePicker::getImplementationName()
770 	throw(uno::RuntimeException)
771 {
772 	return rtl::OUString::createFromAscii(FILE_PICKER_IMPL_NAME);
773 }
774 
775 // -------------------------------------------------
776 //	XServiceInfo
777 // -------------------------------------------------
778 
779 sal_Bool SAL_CALL CFilePicker::supportsService(const rtl::OUString& ServiceName)
780 	throw(uno::RuntimeException )
781 {
782 	uno::Sequence <rtl::OUString> SupportedServicesNames = FilePicker_getSupportedServiceNames();
783 
784 	for (sal_Int32 n = SupportedServicesNames.getLength(); n--;)
785 		if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
786 			return sal_True;
787 
788 	return sal_False;
789 }
790 
791 // -------------------------------------------------
792 //	XServiceInfo
793 // -------------------------------------------------
794 
795 uno::Sequence<rtl::OUString> SAL_CALL CFilePicker::getSupportedServiceNames()
796 	throw(uno::RuntimeException)
797 {
798 	return FilePicker_getSupportedServiceNames();
799 }
800