1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d119d52dSAndrew Rist  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19d119d52dSAndrew Rist  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
2445fd3b9aSArmin Le Grand 
25cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
26cdf0e10cSrcweir #include <sal/types.h>
27cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
28cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
29cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ControlActions.hpp>
33cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XControlInformation.hpp>
35cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
36cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
38cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
39cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
40cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
41cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
42cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
43cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
44cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
45cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
46cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
47cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp>
48cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp>
49cdf0e10cSrcweir #include <com/sun/star/task/XInteractionRequest.hpp>
50cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
53cdf0e10cSrcweir #include <comphelper/types.hxx>
54cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
55cdf0e10cSrcweir #include <comphelper/stillreadwriteinteraction.hxx>
56cdf0e10cSrcweir #include <tools/urlobj.hxx>
57cdf0e10cSrcweir #include <vcl/help.hxx>
58cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
59cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
60cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
61cdf0e10cSrcweir #include <vos/thread.hxx>
62cdf0e10cSrcweir #include <vos/mutex.hxx>
63cdf0e10cSrcweir #include <vos/security.hxx>
64cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
65cdf0e10cSrcweir #include <vcl/msgbox.hxx>
66cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
67cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
68cdf0e10cSrcweir #include <unotools/securityoptions.hxx>
69cdf0e10cSrcweir #include <svl/itemset.hxx>
70cdf0e10cSrcweir #include <svl/eitem.hxx>
71cdf0e10cSrcweir #include <svl/intitem.hxx>
72cdf0e10cSrcweir #include <svl/stritem.hxx>
73cdf0e10cSrcweir #include <svtools/filter.hxx>
74cdf0e10cSrcweir #include <unotools/viewoptions.hxx>
75cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
76cdf0e10cSrcweir #include <svtools/helpid.hrc>
77cdf0e10cSrcweir #include <comphelper/docpasswordrequest.hxx>
78cdf0e10cSrcweir #include <comphelper/docpasswordhelper.hxx>
79cdf0e10cSrcweir #include <ucbhelper/content.hxx>
80cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx>
81cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
82cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
83cdf0e10cSrcweir #include <sfx2/app.hxx>
84cdf0e10cSrcweir #include <sfx2/frame.hxx>
85cdf0e10cSrcweir #include <sfx2/docfile.hxx>
86cdf0e10cSrcweir #include <sfx2/docfac.hxx>
87cdf0e10cSrcweir #include "openflag.hxx"
88cdf0e10cSrcweir #include <sfx2/passwd.hxx>
89cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
90cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
91cdf0e10cSrcweir #include "filedlghelper.hrc"
92cdf0e10cSrcweir #include "filtergrouping.hxx"
93cdf0e10cSrcweir #include <sfx2/request.hxx>
94cdf0e10cSrcweir #include "filedlgimpl.hxx"
95cdf0e10cSrcweir #include <helpid.hrc>
96cdf0e10cSrcweir #include <sfxlocal.hrc>
9745fd3b9aSArmin Le Grand #include <vcl/dibtools.hxx>
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //-----------------------------------------------------------------------------
100cdf0e10cSrcweir 
101cdf0e10cSrcweir using namespace ::com::sun::star;
102cdf0e10cSrcweir using namespace ::com::sun::star::container;
103cdf0e10cSrcweir using namespace ::com::sun::star::lang;
104cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
105cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
106cdf0e10cSrcweir using namespace ::com::sun::star::uno;
107cdf0e10cSrcweir using namespace ::com::sun::star::beans;
108cdf0e10cSrcweir using namespace ::rtl;
109cdf0e10cSrcweir using namespace ::cppu;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //-----------------------------------------------------------------------------
112cdf0e10cSrcweir 
113cdf0e10cSrcweir #define IODLG_CONFIGNAME		String(DEFINE_CONST_UNICODE("FilePicker_Save"))
114cdf0e10cSrcweir #define IMPGRF_CONFIGNAME		String(DEFINE_CONST_UNICODE("FilePicker_Graph"))
115cdf0e10cSrcweir #define USERITEM_NAME			::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UserItem" ))
116cdf0e10cSrcweir 
117cdf0e10cSrcweir //-----------------------------------------------------------------------------
118cdf0e10cSrcweir 
119cdf0e10cSrcweir namespace sfx2
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 
GetLastFilterConfigId(FileDialogHelper::Context _eContext)122cdf0e10cSrcweir const OUString* GetLastFilterConfigId( FileDialogHelper::Context _eContext )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     static const OUString aSD_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SdExportLastFilter" ) );
125cdf0e10cSrcweir     static const OUString aSI_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SiExportLastFilter" ) );
126cdf0e10cSrcweir     static const OUString aSW_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SwExportLastFilter" ) );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     const OUString* pRet = NULL;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     switch( _eContext )
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         case FileDialogHelper::SD_EXPORT: pRet = &aSD_EXPORT_IDENTIFIER; break;
133cdf0e10cSrcweir         case FileDialogHelper::SI_EXPORT: pRet = &aSI_EXPORT_IDENTIFIER; break;
134cdf0e10cSrcweir         case FileDialogHelper::SW_EXPORT: pRet = &aSW_EXPORT_IDENTIFIER; break;
135cdf0e10cSrcweir         default: break;
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     return pRet;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir String EncodeSpaces_Impl( const String& rSource );
142cdf0e10cSrcweir String DecodeSpaces_Impl( const String& rSource );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir // ------------------------------------------------------------------------
145cdf0e10cSrcweir // -----------		FileDialogHelper_Impl		---------------------------
146cdf0e10cSrcweir // ------------------------------------------------------------------------
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // ------------------------------------------------------------------------
149cdf0e10cSrcweir // XFilePickerListener Methods
150cdf0e10cSrcweir // ------------------------------------------------------------------------
fileSelectionChanged(const FilePickerEvent & aEvent)151cdf0e10cSrcweir void SAL_CALL FileDialogHelper_Impl::fileSelectionChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
154cdf0e10cSrcweir 	mpAntiImpl->FileSelectionChanged( aEvent );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // ------------------------------------------------------------------------
directoryChanged(const FilePickerEvent & aEvent)158cdf0e10cSrcweir void SAL_CALL FileDialogHelper_Impl::directoryChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
161cdf0e10cSrcweir 	mpAntiImpl->DirectoryChanged( aEvent );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // ------------------------------------------------------------------------
helpRequested(const FilePickerEvent & aEvent)165cdf0e10cSrcweir OUString SAL_CALL FileDialogHelper_Impl::helpRequested( const FilePickerEvent& aEvent ) throw ( RuntimeException )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
168cdf0e10cSrcweir 	return mpAntiImpl->HelpRequested( aEvent );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // ------------------------------------------------------------------------
controlStateChanged(const FilePickerEvent & aEvent)172cdf0e10cSrcweir void SAL_CALL FileDialogHelper_Impl::controlStateChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
175cdf0e10cSrcweir 	mpAntiImpl->ControlStateChanged( aEvent );
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir // ------------------------------------------------------------------------
dialogSizeChanged()179cdf0e10cSrcweir void SAL_CALL FileDialogHelper_Impl::dialogSizeChanged() throw ( RuntimeException )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
182cdf0e10cSrcweir 	mpAntiImpl->DialogSizeChanged();
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir // ------------------------------------------------------------------------
186cdf0e10cSrcweir // XDialogClosedListener Methods
187cdf0e10cSrcweir // ------------------------------------------------------------------------
dialogClosed(const DialogClosedEvent & _rEvent)188cdf0e10cSrcweir void SAL_CALL FileDialogHelper_Impl::dialogClosed( const DialogClosedEvent& _rEvent ) throw ( RuntimeException )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
191cdf0e10cSrcweir     mpAntiImpl->DialogClosed( _rEvent );
192cdf0e10cSrcweir     postExecute( _rEvent.DialogResult );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir // ------------------------------------------------------------------------
196cdf0e10cSrcweir // handle XFilePickerListener events
197cdf0e10cSrcweir // ------------------------------------------------------------------------
handleFileSelectionChanged(const FilePickerEvent &)198cdf0e10cSrcweir void FileDialogHelper_Impl::handleFileSelectionChanged( const FilePickerEvent& )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	if ( mbHasVersions )
201cdf0e10cSrcweir 		updateVersions();
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	if ( mbShowPreview )
204cdf0e10cSrcweir 		maPreViewTimer.Start();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir // ------------------------------------------------------------------------
handleDirectoryChanged(const FilePickerEvent &)208cdf0e10cSrcweir void FileDialogHelper_Impl::handleDirectoryChanged( const FilePickerEvent& )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	if ( mbShowPreview )
211cdf0e10cSrcweir 		TimeOutHdl_Impl( NULL );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir // ------------------------------------------------------------------------
handleHelpRequested(const FilePickerEvent & aEvent)215cdf0e10cSrcweir OUString FileDialogHelper_Impl::handleHelpRequested( const FilePickerEvent& aEvent )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	//!!! todo: cache the help strings (here or TRA)
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	rtl::OString sHelpId;
220cdf0e10cSrcweir 	// mapping from element id -> help id
221cdf0e10cSrcweir 	switch ( aEvent.ElementId )
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION :
224cdf0e10cSrcweir 			sHelpId = HID_FILESAVE_AUTOEXTENSION;
225cdf0e10cSrcweir 			break;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
228cdf0e10cSrcweir 			sHelpId = HID_FILESAVE_SAVEWITHPASSWORD;
229cdf0e10cSrcweir 			break;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
232cdf0e10cSrcweir 			sHelpId = HID_FILESAVE_CUSTOMIZEFILTER;
233cdf0e10cSrcweir 			break;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_READONLY :
236cdf0e10cSrcweir 			sHelpId = HID_FILEOPEN_READONLY;
237cdf0e10cSrcweir 			break;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_LINK :
240cdf0e10cSrcweir 			sHelpId = HID_FILEDLG_LINK_CB;
241cdf0e10cSrcweir 			break;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW :
244cdf0e10cSrcweir 			sHelpId = HID_FILEDLG_PREVIEW_CB;
245cdf0e10cSrcweir 			break;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY :
248cdf0e10cSrcweir 			sHelpId = HID_FILESAVE_DOPLAY;
249cdf0e10cSrcweir 			break;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL :
252cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::LISTBOX_VERSION :
253cdf0e10cSrcweir 			sHelpId = HID_FILEOPEN_VERSION;
254cdf0e10cSrcweir 			break;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL :
257cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
258cdf0e10cSrcweir 			sHelpId = HID_FILESAVE_TEMPLATE;
259cdf0e10cSrcweir 			break;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL :
262cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
263cdf0e10cSrcweir 			sHelpId = HID_FILEOPEN_IMAGE_TEMPLATE;
264cdf0e10cSrcweir 			break;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
267cdf0e10cSrcweir 			sHelpId = HID_FILESAVE_SELECTION;
268cdf0e10cSrcweir 			break;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 		default:
271cdf0e10cSrcweir 			DBG_ERRORFILE( "invalid element id" );
272cdf0e10cSrcweir 	}
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	OUString aHelpText;
275cdf0e10cSrcweir 	Help* pHelp = Application::GetHelp();
276cdf0e10cSrcweir 	if ( pHelp )
277cdf0e10cSrcweir 		aHelpText = String( pHelp->GetHelpText( String( ByteString(sHelpId), RTL_TEXTENCODING_UTF8), NULL ) );
278cdf0e10cSrcweir 	return aHelpText;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir // ------------------------------------------------------------------------
handleControlStateChanged(const FilePickerEvent & aEvent)282cdf0e10cSrcweir void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aEvent )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir 	switch ( aEvent.ElementId )
285cdf0e10cSrcweir 	{
286cdf0e10cSrcweir 		case CommonFilePickerElementIds::LISTBOX_FILTER:
287cdf0e10cSrcweir 			updateFilterOptionsBox();
288cdf0e10cSrcweir 			enablePasswordBox( sal_False );
289cdf0e10cSrcweir 			updateSelectionBox();
290cdf0e10cSrcweir 			// only use it for export and with our own dialog
291cdf0e10cSrcweir 			if ( mbExport && !mbSystemPicker )
292cdf0e10cSrcweir 				updateExportButton();
293cdf0e10cSrcweir 			break;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 		case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
296cdf0e10cSrcweir 			updatePreviewState();
297cdf0e10cSrcweir 			break;
298cdf0e10cSrcweir 	}
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir // ------------------------------------------------------------------------
handleDialogSizeChanged()302cdf0e10cSrcweir void FileDialogHelper_Impl::handleDialogSizeChanged()
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     if ( mbShowPreview )
305cdf0e10cSrcweir         TimeOutHdl_Impl( NULL );
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir // ------------------------------------------------------------------------
309cdf0e10cSrcweir // XEventListener Methods
310cdf0e10cSrcweir // ------------------------------------------------------------------------
disposing(const EventObject &)311cdf0e10cSrcweir void SAL_CALL FileDialogHelper_Impl::disposing( const EventObject& ) throw ( RuntimeException )
312cdf0e10cSrcweir {
313cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
314cdf0e10cSrcweir 	dispose();
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir // ------------------------------------------------------------------------
318cdf0e10cSrcweir // ------------------------------------------------------------------------
319cdf0e10cSrcweir // ------------------------------------------------------------------------
dispose()320cdf0e10cSrcweir void FileDialogHelper_Impl::dispose()
321cdf0e10cSrcweir {
322cdf0e10cSrcweir 	if ( mxFileDlg.is() )
323cdf0e10cSrcweir 	{
324cdf0e10cSrcweir 		// remove the event listener
325cdf0e10cSrcweir 		uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
326cdf0e10cSrcweir 		if ( xNotifier.is() )
327cdf0e10cSrcweir 			xNotifier->removeFilePickerListener( this );
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 		::comphelper::disposeComponent( mxFileDlg );
330cdf0e10cSrcweir 		mxFileDlg.clear();
331cdf0e10cSrcweir 	}
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir // ------------------------------------------------------------------------
getCurrentFilterUIName() const335cdf0e10cSrcweir String FileDialogHelper_Impl::getCurrentFilterUIName() const
336cdf0e10cSrcweir {
337cdf0e10cSrcweir 	String aFilterName;
338cdf0e10cSrcweir 	uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	if( xFltMgr.is() )
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 		aFilterName = xFltMgr->getCurrentFilter();
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 		if ( aFilterName.Len() && isShowFilterExtensionEnabled() )
345cdf0e10cSrcweir 			aFilterName = getFilterName( aFilterName );
346cdf0e10cSrcweir 	}
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 	return aFilterName;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir // ------------------------------------------------------------------------
LoadLastUsedFilter(const OUString & _rContextIdentifier)352cdf0e10cSrcweir void FileDialogHelper_Impl::LoadLastUsedFilter( const OUString& _rContextIdentifier )
353cdf0e10cSrcweir {
354cdf0e10cSrcweir 	SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	if( aDlgOpt.Exists() )
357cdf0e10cSrcweir 	{
358cdf0e10cSrcweir 		OUString	aLastFilter;
359cdf0e10cSrcweir 		if( aDlgOpt.GetUserItem( _rContextIdentifier ) >>= aLastFilter )
360cdf0e10cSrcweir 			setFilter( aLastFilter );
361cdf0e10cSrcweir 	}
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir // ------------------------------------------------------------------------
SaveLastUsedFilter(const OUString & _rContextIdentifier)365cdf0e10cSrcweir void FileDialogHelper_Impl::SaveLastUsedFilter( const OUString& _rContextIdentifier )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir 	SvtViewOptions( E_DIALOG, IODLG_CONFIGNAME ).SetUserItem( _rContextIdentifier,
368cdf0e10cSrcweir 						makeAny( getFilterWithExtension( getFilter() ) ) );
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir // ------------------------------------------------------------------------
SaveLastUsedFilter(void)372cdf0e10cSrcweir void FileDialogHelper_Impl::SaveLastUsedFilter( void )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir 	const OUString*	pConfigId = GetLastFilterConfigId( meContext );
375cdf0e10cSrcweir 	if( pConfigId )
376cdf0e10cSrcweir 		SaveLastUsedFilter( *pConfigId );
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir // ------------------------------------------------------------------------
getCurentSfxFilter()380cdf0e10cSrcweir const SfxFilter* FileDialogHelper_Impl::getCurentSfxFilter()
381cdf0e10cSrcweir {
382cdf0e10cSrcweir 	String aFilterName = getCurrentFilterUIName();
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	const SfxFilter* pFilter = NULL;
385cdf0e10cSrcweir 	if ( mpMatcher && aFilterName.Len() )
386cdf0e10cSrcweir 		pFilter = mpMatcher->GetFilter4UIName( aFilterName, m_nMustFlags, m_nDontFlags );
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 	return pFilter;
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir // ------------------------------------------------------------------------
updateExtendedControl(sal_Int16 _nExtendedControlId,sal_Bool _bEnable)392cdf0e10cSrcweir sal_Bool FileDialogHelper_Impl::updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir 	sal_Bool bIsEnabled = sal_False;
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 	uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
397cdf0e10cSrcweir 	if ( xCtrlAccess.is() )
398cdf0e10cSrcweir 	{
399cdf0e10cSrcweir 		try
400cdf0e10cSrcweir 		{
401cdf0e10cSrcweir 			xCtrlAccess->enableControl( _nExtendedControlId, _bEnable );
402cdf0e10cSrcweir 			bIsEnabled = _bEnable;
403cdf0e10cSrcweir 		}
404cdf0e10cSrcweir 		catch( const IllegalArgumentException& )
405cdf0e10cSrcweir 		{
406cdf0e10cSrcweir 			DBG_ERROR( "FileDialogHelper_Impl::updateExtendedControl: caught an exception!" );
407cdf0e10cSrcweir 		}
408cdf0e10cSrcweir 	}
409cdf0e10cSrcweir 	return bIsEnabled;
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir // ------------------------------------------------------------------------
CheckFilterOptionsCapability(const SfxFilter * _pFilter)413cdf0e10cSrcweir sal_Bool FileDialogHelper_Impl::CheckFilterOptionsCapability( const SfxFilter* _pFilter )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 	if( mxFilterCFG.is() && _pFilter )
418cdf0e10cSrcweir 	{
419cdf0e10cSrcweir 		try {
420cdf0e10cSrcweir    			Sequence < PropertyValue > aProps;
421cdf0e10cSrcweir    			Any aAny = mxFilterCFG->getByName( _pFilter->GetName() );
422cdf0e10cSrcweir    			if ( aAny >>= aProps )
423cdf0e10cSrcweir    			{
424cdf0e10cSrcweir        			::rtl::OUString aServiceName;
425cdf0e10cSrcweir        			sal_Int32 nPropertyCount = aProps.getLength();
426cdf0e10cSrcweir        			for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
427cdf0e10cSrcweir 				{
428cdf0e10cSrcweir            			if( aProps[nProperty].Name.equals( DEFINE_CONST_OUSTRING( "UIComponent") ) )
429cdf0e10cSrcweir            			{
430cdf0e10cSrcweir                			aProps[nProperty].Value >>= aServiceName;
431cdf0e10cSrcweir 						if( aServiceName.getLength() )
432cdf0e10cSrcweir 							bResult = sal_True;
433cdf0e10cSrcweir 					}
434cdf0e10cSrcweir 				}
435cdf0e10cSrcweir 			}
436cdf0e10cSrcweir 		}
437cdf0e10cSrcweir 		catch( Exception& )
438cdf0e10cSrcweir 		{
439cdf0e10cSrcweir 		}
440cdf0e10cSrcweir 	}
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 	return bResult;
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir // ------------------------------------------------------------------------
isInOpenMode() const446cdf0e10cSrcweir sal_Bool FileDialogHelper_Impl::isInOpenMode() const
447cdf0e10cSrcweir {
448cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 	switch ( m_nDialogType )
451cdf0e10cSrcweir 	{
452cdf0e10cSrcweir 		case FILEOPEN_SIMPLE:
453cdf0e10cSrcweir 		case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
454cdf0e10cSrcweir 		case FILEOPEN_PLAY:
455cdf0e10cSrcweir 		case FILEOPEN_READONLY_VERSION:
456cdf0e10cSrcweir 		case FILEOPEN_LINK_PREVIEW:
457cdf0e10cSrcweir 			bRet = sal_True;
458cdf0e10cSrcweir 	}
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	return bRet;
461cdf0e10cSrcweir }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir // ------------------------------------------------------------------------
464cdf0e10cSrcweir 
updateFilterOptionsBox()465cdf0e10cSrcweir void FileDialogHelper_Impl::updateFilterOptionsBox()
466cdf0e10cSrcweir {
467cdf0e10cSrcweir 	if ( !m_bHaveFilterOptions )
468cdf0e10cSrcweir 		return;
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 	updateExtendedControl(
471cdf0e10cSrcweir 		ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS,
472cdf0e10cSrcweir 		CheckFilterOptionsCapability( getCurentSfxFilter() )
473cdf0e10cSrcweir 	);
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir // ------------------------------------------------------------------------
477cdf0e10cSrcweir 
updateExportButton()478cdf0e10cSrcweir void FileDialogHelper_Impl::updateExportButton()
479cdf0e10cSrcweir {
480cdf0e10cSrcweir 	uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
481cdf0e10cSrcweir 	if ( xCtrlAccess.is() )
482cdf0e10cSrcweir 	{
483cdf0e10cSrcweir 		OUString sEllipses( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
484cdf0e10cSrcweir 		OUString sOldLabel( xCtrlAccess->getLabel( CommonFilePickerElementIds::PUSHBUTTON_OK ) );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 		// initialize button label; we need the label with the mnemonic char
487cdf0e10cSrcweir 		if ( !maButtonLabel.getLength() || maButtonLabel.indexOf( MNEMONIC_CHAR ) == -1 )
488cdf0e10cSrcweir 		{
489cdf0e10cSrcweir 			// cut the ellipses, if necessary
490cdf0e10cSrcweir 			sal_Int32 nIndex = sOldLabel.indexOf( sEllipses );
491cdf0e10cSrcweir 			if ( -1 == nIndex )
492cdf0e10cSrcweir 				nIndex = sOldLabel.getLength();
493cdf0e10cSrcweir 			maButtonLabel = sOldLabel.copy( 0, nIndex );
494cdf0e10cSrcweir 		}
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 		OUString sLabel = maButtonLabel;
497cdf0e10cSrcweir 		// filter with options -> append ellipses on export button label
498cdf0e10cSrcweir 		if ( CheckFilterOptionsCapability( getCurentSfxFilter() ) )
499cdf0e10cSrcweir 			sLabel += OUString( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 		if ( sOldLabel != sLabel )
502cdf0e10cSrcweir 		{
503cdf0e10cSrcweir 			try
504cdf0e10cSrcweir 			{
505cdf0e10cSrcweir 				xCtrlAccess->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, sLabel );
506cdf0e10cSrcweir 			}
507cdf0e10cSrcweir 			catch( const IllegalArgumentException& )
508cdf0e10cSrcweir 			{
509cdf0e10cSrcweir 				DBG_ERRORFILE( "FileDialogHelper_Impl::updateExportButton: caught an exception!" );
510cdf0e10cSrcweir 			}
511cdf0e10cSrcweir 		}
512cdf0e10cSrcweir 	}
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir // ------------------------------------------------------------------------
updateSelectionBox()516cdf0e10cSrcweir void FileDialogHelper_Impl::updateSelectionBox()
517cdf0e10cSrcweir {
518cdf0e10cSrcweir 	if ( !mbHasSelectionBox )
519cdf0e10cSrcweir 		return;
520cdf0e10cSrcweir 
521cdf0e10cSrcweir     // Does the selection box exist?
522cdf0e10cSrcweir     sal_Bool bSelectionBoxFound = sal_False;
523cdf0e10cSrcweir     uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY );
524cdf0e10cSrcweir     if ( xCtrlInfo.is() )
525cdf0e10cSrcweir     {
526cdf0e10cSrcweir         Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls();
527cdf0e10cSrcweir         sal_uInt32 nCount = aCtrlList.getLength();
528cdf0e10cSrcweir         for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl )
529cdf0e10cSrcweir             if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") )
530cdf0e10cSrcweir             {
531cdf0e10cSrcweir                 bSelectionBoxFound = sal_False;
532cdf0e10cSrcweir                 break;
533cdf0e10cSrcweir             }
534cdf0e10cSrcweir     }
535cdf0e10cSrcweir 
536cdf0e10cSrcweir     if ( bSelectionBoxFound )
537cdf0e10cSrcweir     {
538cdf0e10cSrcweir         const SfxFilter* pFilter = getCurentSfxFilter();
539cdf0e10cSrcweir         mbSelectionFltrEnabled = updateExtendedControl(
540cdf0e10cSrcweir             ExtendedFilePickerElementIds::CHECKBOX_SELECTION,
541cdf0e10cSrcweir             ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) );
542cdf0e10cSrcweir         uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
543cdf0e10cSrcweir         xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) );
544cdf0e10cSrcweir     }
545cdf0e10cSrcweir }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir // ------------------------------------------------------------------------
enablePasswordBox(sal_Bool bInit)548cdf0e10cSrcweir void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit )
549cdf0e10cSrcweir {
550cdf0e10cSrcweir 	if ( ! mbHasPassword )
551cdf0e10cSrcweir 		return;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 	sal_Bool bWasEnabled = mbIsPwdEnabled;
554cdf0e10cSrcweir 
555cdf0e10cSrcweir     const SfxFilter* pCurrentFilter = getCurentSfxFilter();
556cdf0e10cSrcweir 	mbIsPwdEnabled = updateExtendedControl(
557cdf0e10cSrcweir 		ExtendedFilePickerElementIds::CHECKBOX_PASSWORD,
558cdf0e10cSrcweir         pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION )
559cdf0e10cSrcweir 	);
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 	if( bInit )
562cdf0e10cSrcweir 	{
563cdf0e10cSrcweir 		// in case of inintialization previous state is not interesting
564cdf0e10cSrcweir 		if( mbIsPwdEnabled )
565cdf0e10cSrcweir 		{
566cdf0e10cSrcweir 			uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
567cdf0e10cSrcweir 			if( mbPwdCheckBoxState )
568cdf0e10cSrcweir 				xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
569cdf0e10cSrcweir 		}
570cdf0e10cSrcweir 	}
571cdf0e10cSrcweir 	else if( !bWasEnabled && mbIsPwdEnabled )
572cdf0e10cSrcweir 	{
573cdf0e10cSrcweir 		uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
574cdf0e10cSrcweir 		if( mbPwdCheckBoxState )
575cdf0e10cSrcweir 			xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
576cdf0e10cSrcweir 	}
577cdf0e10cSrcweir 	else if( bWasEnabled && !mbIsPwdEnabled )
578cdf0e10cSrcweir 	{
579cdf0e10cSrcweir 		// remember user settings until checkbox is enabled
580cdf0e10cSrcweir 		uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
581cdf0e10cSrcweir 		Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
582cdf0e10cSrcweir 		sal_Bool bPassWord = sal_False;
583cdf0e10cSrcweir 		mbPwdCheckBoxState = ( aValue >>= bPassWord ) && bPassWord;
584cdf0e10cSrcweir 		xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_False ) );
585cdf0e10cSrcweir 	}
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir // ------------------------------------------------------------------------
updatePreviewState(sal_Bool _bUpdatePreviewWindow)589cdf0e10cSrcweir void FileDialogHelper_Impl::updatePreviewState( sal_Bool _bUpdatePreviewWindow )
590cdf0e10cSrcweir {
591cdf0e10cSrcweir 	if ( mbHasPreview )
592cdf0e10cSrcweir 	{
593cdf0e10cSrcweir 		uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 		// check, wether or not we have to display a preview
596cdf0e10cSrcweir 		if ( xCtrlAccess.is() )
597cdf0e10cSrcweir 		{
598cdf0e10cSrcweir 			try
599cdf0e10cSrcweir 			{
600cdf0e10cSrcweir 				Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
601cdf0e10cSrcweir 				sal_Bool bShowPreview = sal_False;
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 				if ( aValue >>= bShowPreview )
604cdf0e10cSrcweir 				{
605cdf0e10cSrcweir 					mbShowPreview = bShowPreview;
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 					// #97633
608cdf0e10cSrcweir 					// setShowState has currently no effect for the
609cdf0e10cSrcweir 					// OpenOffice FilePicker (see svtools/source/filepicker/iodlg.cxx)
610cdf0e10cSrcweir 					uno::Reference< XFilePreview > xFilePreview( mxFileDlg, UNO_QUERY );
611cdf0e10cSrcweir 					if ( xFilePreview.is() )
612cdf0e10cSrcweir 						xFilePreview->setShowState( mbShowPreview );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 					if ( _bUpdatePreviewWindow )
615cdf0e10cSrcweir 						TimeOutHdl_Impl( NULL );
616cdf0e10cSrcweir 				}
617cdf0e10cSrcweir 			}
618cdf0e10cSrcweir 			catch( Exception )
619cdf0e10cSrcweir 			{
620cdf0e10cSrcweir 				DBG_ERRORFILE( "FileDialogHelper_Impl::updatePreviewState: caught an exception!" );
621cdf0e10cSrcweir 			}
622cdf0e10cSrcweir 		}
623cdf0e10cSrcweir 	}
624cdf0e10cSrcweir }
625cdf0e10cSrcweir 
626cdf0e10cSrcweir // ------------------------------------------------------------------------
updateVersions()627cdf0e10cSrcweir void FileDialogHelper_Impl::updateVersions()
628cdf0e10cSrcweir {
629cdf0e10cSrcweir 	Sequence < OUString > aEntries;
630cdf0e10cSrcweir 	Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 	if ( aPathSeq.getLength() == 1 )
633cdf0e10cSrcweir 	{
634cdf0e10cSrcweir 		INetURLObject aObj( aPathSeq[0] );
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 		if ( ( aObj.GetProtocol() == INET_PROT_FILE ) &&
637cdf0e10cSrcweir 			( utl::UCBContentHelper::IsDocument( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) )
638cdf0e10cSrcweir 		{
639cdf0e10cSrcweir 			try
640cdf0e10cSrcweir 			{
641cdf0e10cSrcweir 				uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
642cdf0e10cSrcweir 																aObj.GetMainURL( INetURLObject::NO_DECODE ),
643cdf0e10cSrcweir 																embed::ElementModes::READ );
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 				DBG_ASSERT( xStorage.is(), "The method must return the storage or throw an exception!" );
646cdf0e10cSrcweir 				if ( !xStorage.is() )
647cdf0e10cSrcweir 					throw uno::RuntimeException();
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 				uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
650cdf0e10cSrcweir 
651cdf0e10cSrcweir                 aEntries.realloc( xVersions.getLength() + 1 );
652cdf0e10cSrcweir                 aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
653cdf0e10cSrcweir 
654cdf0e10cSrcweir                 for ( sal_Int32 i=0; i<xVersions.getLength(); i++ )
655cdf0e10cSrcweir                     aEntries[ i + 1 ] = xVersions[i].Identifier;
656cdf0e10cSrcweir 
657cdf0e10cSrcweir                 // TODO/LATER: not sure that this information must be shown in future ( binfilter? )
658cdf0e10cSrcweir //REMOVE					else
659cdf0e10cSrcweir //REMOVE					{
660cdf0e10cSrcweir //REMOVE						SfxFilterFlags nMust = SFX_FILTER_IMPORT | SFX_FILTER_OWN;
661cdf0e10cSrcweir //REMOVE						SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED | SFX_FILTER_STARONEFILTER;
662cdf0e10cSrcweir //REMOVE						if ( SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( pStor->GetFormat(), nMust, nDont ) )
663cdf0e10cSrcweir //REMOVE						{
664cdf0e10cSrcweir //REMOVE							aEntries.realloc( 1 );
665cdf0e10cSrcweir //REMOVE							aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
666cdf0e10cSrcweir //REMOVE						}
667cdf0e10cSrcweir //REMOVE					}
668cdf0e10cSrcweir 			}
669cdf0e10cSrcweir 			catch( uno::Exception& )
670cdf0e10cSrcweir 			{
671cdf0e10cSrcweir 			}
672cdf0e10cSrcweir 		}
673cdf0e10cSrcweir 	}
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 	uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
676cdf0e10cSrcweir 	Any aValue;
677cdf0e10cSrcweir 
678cdf0e10cSrcweir 	try
679cdf0e10cSrcweir 	{
680cdf0e10cSrcweir 		xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
681cdf0e10cSrcweir 						ControlActions::DELETE_ITEMS, aValue );
682cdf0e10cSrcweir 	}
683cdf0e10cSrcweir 	catch( IllegalArgumentException ){}
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 	sal_Int32 nCount = aEntries.getLength();
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 	if ( nCount )
688cdf0e10cSrcweir 	{
689cdf0e10cSrcweir 		try
690cdf0e10cSrcweir 		{
691cdf0e10cSrcweir 			aValue <<= aEntries;
692cdf0e10cSrcweir 			xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
693cdf0e10cSrcweir 							ControlActions::ADD_ITEMS, aValue );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir 			Any aPos;
696cdf0e10cSrcweir 			aPos <<= (sal_Int32) 0;
697cdf0e10cSrcweir 			xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
698cdf0e10cSrcweir 							ControlActions::SET_SELECT_ITEM, aPos );
699cdf0e10cSrcweir 		}
700cdf0e10cSrcweir 		catch( IllegalArgumentException ){}
701cdf0e10cSrcweir 	}
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir // -----------------------------------------------------------------------
705cdf0e10cSrcweir class OReleaseSolarMutex
706cdf0e10cSrcweir {
707cdf0e10cSrcweir private:
708cdf0e10cSrcweir 	const sal_Int32	m_nAquireCount;
709cdf0e10cSrcweir public:
OReleaseSolarMutex()710cdf0e10cSrcweir 	OReleaseSolarMutex( )
711cdf0e10cSrcweir 		:m_nAquireCount( Application::ReleaseSolarMutex() )
712cdf0e10cSrcweir 	{
713cdf0e10cSrcweir 	}
~OReleaseSolarMutex()714cdf0e10cSrcweir 	~OReleaseSolarMutex( )
715cdf0e10cSrcweir 	{
716cdf0e10cSrcweir 		Application::AcquireSolarMutex( m_nAquireCount );
717cdf0e10cSrcweir 	}
718cdf0e10cSrcweir };
719cdf0e10cSrcweir 
720cdf0e10cSrcweir // -----------------------------------------------------------------------
IMPL_LINK(FileDialogHelper_Impl,TimeOutHdl_Impl,Timer *,EMPTYARG)721cdf0e10cSrcweir IMPL_LINK( FileDialogHelper_Impl, TimeOutHdl_Impl, Timer*, EMPTYARG )
722cdf0e10cSrcweir {
723cdf0e10cSrcweir 	if ( !mbHasPreview )
724cdf0e10cSrcweir 		return 0;
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 	maGraphic.Clear();
727cdf0e10cSrcweir 
728cdf0e10cSrcweir 	Any aAny;
729cdf0e10cSrcweir 	uno::Reference < XFilePreview > xFilePicker( mxFileDlg, UNO_QUERY );
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 	if ( ! xFilePicker.is() )
732cdf0e10cSrcweir 		return 0;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 	Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 	if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) )
737cdf0e10cSrcweir 	{
738cdf0e10cSrcweir 		OUString	aURL = aPathSeq[0];
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 		if ( ERRCODE_NONE == getGraphic( aURL, maGraphic ) )
741cdf0e10cSrcweir 		{
742cdf0e10cSrcweir 			// #89491
743cdf0e10cSrcweir 			// changed the code slightly;
744cdf0e10cSrcweir 			// before: the bitmap was scaled and
745cdf0e10cSrcweir 			// surrounded a white frame
746cdf0e10cSrcweir 			// now: the bitmap will only be scaled
747cdf0e10cSrcweir 			// and the filepicker implementation
748cdf0e10cSrcweir 			// is responsible for placing it at its
749cdf0e10cSrcweir 			// proper position and painting a frame
750cdf0e10cSrcweir 
751cdf0e10cSrcweir 			Bitmap aBmp = maGraphic.GetBitmap();
75227ac3209SAriel Constenla-Haile             if ( !aBmp.IsEmpty() )
75327ac3209SAriel Constenla-Haile             {
75427ac3209SAriel Constenla-Haile                 // scale the bitmap to the correct size
75527ac3209SAriel Constenla-Haile                 sal_Int32 nOutWidth  = xFilePicker->getAvailableWidth();
75627ac3209SAriel Constenla-Haile                 sal_Int32 nOutHeight = xFilePicker->getAvailableHeight();
75727ac3209SAriel Constenla-Haile                 sal_Int32 nBmpWidth  = aBmp.GetSizePixel().Width();
75827ac3209SAriel Constenla-Haile                 sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
759cdf0e10cSrcweir 
76027ac3209SAriel Constenla-Haile                 double nXRatio = (double) nOutWidth / nBmpWidth;
76127ac3209SAriel Constenla-Haile                 double nYRatio = (double) nOutHeight / nBmpHeight;
762cdf0e10cSrcweir 
76327ac3209SAriel Constenla-Haile                 if ( nXRatio < nYRatio )
76427ac3209SAriel Constenla-Haile                     aBmp.Scale( nXRatio, nXRatio );
76527ac3209SAriel Constenla-Haile                 else
76627ac3209SAriel Constenla-Haile                     aBmp.Scale( nYRatio, nYRatio );
767cdf0e10cSrcweir 
76827ac3209SAriel Constenla-Haile                 // #94505# Convert to true color, to allow CopyPixel
76927ac3209SAriel Constenla-Haile                 aBmp.Convert( BMP_CONVERSION_24BIT );
770cdf0e10cSrcweir 
77127ac3209SAriel Constenla-Haile                 // and copy it into the Any
77227ac3209SAriel Constenla-Haile                 SvMemoryStream aData;
773cdf0e10cSrcweir 
77445fd3b9aSArmin Le Grand                 WriteDIB(aBmp, aData, false, true);
775cdf0e10cSrcweir 
77627ac3209SAriel Constenla-Haile                 const Sequence < sal_Int8 > aBuffer(
77727ac3209SAriel Constenla-Haile                     static_cast< const sal_Int8* >(aData.GetData()),
77827ac3209SAriel Constenla-Haile                     aData.GetEndOfData() );
779cdf0e10cSrcweir 
78027ac3209SAriel Constenla-Haile                 aAny <<= aBuffer;
78127ac3209SAriel Constenla-Haile             }
782cdf0e10cSrcweir 		}
783cdf0e10cSrcweir 	}
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 	try
786cdf0e10cSrcweir 	{
787cdf0e10cSrcweir 		OReleaseSolarMutex aReleaseForCallback;
788cdf0e10cSrcweir 		// clear the preview window
789cdf0e10cSrcweir 		xFilePicker->setImage( FilePreviewImageFormats::BITMAP, aAny );
790cdf0e10cSrcweir 	}
791cdf0e10cSrcweir 	catch( IllegalArgumentException )
792cdf0e10cSrcweir 	{
793cdf0e10cSrcweir 	}
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 	return 0;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir // ------------------------------------------------------------------------
getGraphic(const OUString & rURL,Graphic & rGraphic) const799cdf0e10cSrcweir ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL,
800cdf0e10cSrcweir 										   Graphic& rGraphic ) const
801cdf0e10cSrcweir {
802cdf0e10cSrcweir 	if ( utl::UCBContentHelper::IsFolder( rURL ) )
803cdf0e10cSrcweir 		return ERRCODE_IO_NOTAFILE;
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 	if ( !mpGraphicFilter )
806cdf0e10cSrcweir 		return ERRCODE_IO_NOTSUPPORTED;
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 	// select graphic filter from dialog filter selection
809cdf0e10cSrcweir 	OUString aCurFilter( getFilter() );
810cdf0e10cSrcweir 
811cdf0e10cSrcweir 	sal_uInt16 nFilter = aCurFilter.getLength() && mpGraphicFilter->GetImportFormatCount()
812cdf0e10cSrcweir 					? mpGraphicFilter->GetImportFormatNumber( aCurFilter )
813cdf0e10cSrcweir 					: GRFILTER_FORMAT_DONTKNOW;
814cdf0e10cSrcweir 
815cdf0e10cSrcweir 	INetURLObject aURLObj( rURL );
816cdf0e10cSrcweir 
817cdf0e10cSrcweir 	if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
818cdf0e10cSrcweir 	{
819cdf0e10cSrcweir 		aURLObj.SetSmartProtocol( INET_PROT_FILE );
820cdf0e10cSrcweir 		aURLObj.SetSmartURL( rURL );
821cdf0e10cSrcweir 	}
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 	ErrCode nRet = ERRCODE_NONE;
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 	sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
826cdf0e10cSrcweir 	// non-local?
827cdf0e10cSrcweir 	if ( INET_PROT_FILE != aURLObj.GetProtocol() )
828cdf0e10cSrcweir 	{
829cdf0e10cSrcweir 		SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 		if( pStream )
832cdf0e10cSrcweir 			nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, NULL, nFilterImportFlags );
833cdf0e10cSrcweir 		else
834cdf0e10cSrcweir 			nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
835cdf0e10cSrcweir 		delete pStream;
836cdf0e10cSrcweir 	}
837cdf0e10cSrcweir 	else
838cdf0e10cSrcweir 	{
839cdf0e10cSrcweir 		nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
840cdf0e10cSrcweir 	}
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 	return nRet;
843cdf0e10cSrcweir }
844cdf0e10cSrcweir 
845cdf0e10cSrcweir // ------------------------------------------------------------------------
getGraphic(Graphic & rGraphic) const846cdf0e10cSrcweir ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const
847cdf0e10cSrcweir {
848cdf0e10cSrcweir 	ErrCode nRet = ERRCODE_NONE;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 	if ( ! maGraphic )
851cdf0e10cSrcweir 	{
852cdf0e10cSrcweir 		OUString aPath;;
853cdf0e10cSrcweir 		Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
854cdf0e10cSrcweir 
855cdf0e10cSrcweir 		if ( aPathSeq.getLength() == 1 )
856cdf0e10cSrcweir 		{
857cdf0e10cSrcweir 			aPath = aPathSeq[0];
858cdf0e10cSrcweir 		}
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 		if ( aPath.getLength() )
861cdf0e10cSrcweir 			nRet = getGraphic( aPath, rGraphic );
862cdf0e10cSrcweir 		else
863cdf0e10cSrcweir 			nRet = ERRCODE_IO_GENERAL;
864cdf0e10cSrcweir 	}
865cdf0e10cSrcweir 	else
866cdf0e10cSrcweir 		rGraphic = maGraphic;
867cdf0e10cSrcweir 
868cdf0e10cSrcweir 	return nRet;
869cdf0e10cSrcweir }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir // ------------------------------------------------------------------------
lcl_isSystemFilePicker(const uno::Reference<XFilePicker> & _rxFP)872cdf0e10cSrcweir sal_Bool lcl_isSystemFilePicker( const uno::Reference< XFilePicker >& _rxFP )
873cdf0e10cSrcweir {
874cdf0e10cSrcweir 	try
875cdf0e10cSrcweir 	{
876cdf0e10cSrcweir 		uno::Reference< XServiceInfo > xSI( _rxFP, UNO_QUERY );
877cdf0e10cSrcweir 		if ( xSI.is() && xSI->supportsService( DEFINE_CONST_OUSTRING( "com.sun.star.ui.dialogs.SystemFilePicker" ) ) )
878cdf0e10cSrcweir 			return sal_True;
879cdf0e10cSrcweir 	}
880cdf0e10cSrcweir 	catch( const Exception& )
881cdf0e10cSrcweir 	{
882cdf0e10cSrcweir 	}
883cdf0e10cSrcweir 	return sal_False;
884cdf0e10cSrcweir }
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 
887cdf0e10cSrcweir // ------------------------------------------------------------------------
888cdf0e10cSrcweir // -----------		FileDialogHelper_Impl		---------------------------
889cdf0e10cSrcweir // ------------------------------------------------------------------------
890cdf0e10cSrcweir 
FileDialogHelper_Impl(FileDialogHelper * _pAntiImpl,sal_Int16 nDialogType,sal_Int64 nFlags,sal_Int16 nDialog,Window * _pPreferredParentWindow,const String & sStandardDir,const::com::sun::star::uno::Sequence<::rtl::OUString> & rBlackList)891cdf0e10cSrcweir FileDialogHelper_Impl::FileDialogHelper_Impl(
892cdf0e10cSrcweir 	FileDialogHelper* _pAntiImpl,
893cdf0e10cSrcweir 	sal_Int16 nDialogType,
894cdf0e10cSrcweir 	sal_Int64 nFlags,
895cdf0e10cSrcweir 	sal_Int16 nDialog,
896cdf0e10cSrcweir 	Window* _pPreferredParentWindow,
897cdf0e10cSrcweir 	const String& sStandardDir,
898cdf0e10cSrcweir 	const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
899cdf0e10cSrcweir 	)
900cdf0e10cSrcweir 	:m_nDialogType			( nDialogType )
901cdf0e10cSrcweir 	,meContext				( FileDialogHelper::UNKNOWN_CONTEXT )
902cdf0e10cSrcweir {
903cdf0e10cSrcweir 	const char* pServiceName=0;
904cdf0e10cSrcweir 	if ( nDialog == SFX2_IMPL_DIALOG_SYSTEM )
905cdf0e10cSrcweir 		pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
906cdf0e10cSrcweir 	else if ( nDialog == SFX2_IMPL_DIALOG_OOO )
907cdf0e10cSrcweir 		pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
908cdf0e10cSrcweir 	else
909cdf0e10cSrcweir 		pServiceName = FILE_OPEN_SERVICE_NAME;
910cdf0e10cSrcweir 	OUString aService = ::rtl::OUString::createFromAscii( pServiceName );
911cdf0e10cSrcweir 
912cdf0e10cSrcweir 	uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
913cdf0e10cSrcweir 
914cdf0e10cSrcweir 	// create the file open dialog
915cdf0e10cSrcweir 	// the flags can be SFXWB_INSERT or SFXWB_MULTISELECTION
916cdf0e10cSrcweir 
917cdf0e10cSrcweir 	mpPreferredParentWindow = _pPreferredParentWindow;
918cdf0e10cSrcweir 	mpAntiImpl				= _pAntiImpl;
919cdf0e10cSrcweir 	mnError 				= ERRCODE_NONE;
920cdf0e10cSrcweir 	mbHasAutoExt			= sal_False;
921cdf0e10cSrcweir 	mbHasPassword			= sal_False;
922cdf0e10cSrcweir 	m_bHaveFilterOptions	= sal_False;
923cdf0e10cSrcweir 	mbIsPwdEnabled			= sal_True;
924cdf0e10cSrcweir 	mbHasVersions			= sal_False;
925cdf0e10cSrcweir 	mbHasPreview			= sal_False;
926cdf0e10cSrcweir 	mbShowPreview			= sal_False;
927cdf0e10cSrcweir 	mbHasLink				= sal_False;
928cdf0e10cSrcweir 	mbDeleteMatcher 		= sal_False;
929cdf0e10cSrcweir 	mbInsert				= SFXWB_INSERT == ( nFlags & SFXWB_INSERT );
930cdf0e10cSrcweir 	mbExport				= SFXWB_EXPORT == ( nFlags & SFXWB_EXPORT );
931cdf0e10cSrcweir 	mbIsSaveDlg 			= sal_False;
932cdf0e10cSrcweir 	mbPwdCheckBoxState		= sal_False;
933cdf0e10cSrcweir 	mbSelection				= sal_False;
934cdf0e10cSrcweir 	mbSelectionEnabled		= sal_True;
935cdf0e10cSrcweir 	mbHasSelectionBox       = sal_False;
936cdf0e10cSrcweir 	mbSelectionFltrEnabled  = sal_False;
937cdf0e10cSrcweir 
938cdf0e10cSrcweir 	// default settings
939cdf0e10cSrcweir     m_nDontFlags = SFX_FILTER_INTERNAL | SFX_FILTER_NOTINFILEDLG | SFX_FILTER_NOTINSTALLED;
940cdf0e10cSrcweir 	if( WB_OPEN == ( nFlags & WB_OPEN ) )
941cdf0e10cSrcweir 		m_nMustFlags = SFX_FILTER_IMPORT;
942cdf0e10cSrcweir 	else
943cdf0e10cSrcweir 		m_nMustFlags = SFX_FILTER_EXPORT;
944cdf0e10cSrcweir 
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 	mpMatcher = NULL;
947cdf0e10cSrcweir 	mpGraphicFilter = NULL;
948cdf0e10cSrcweir 	mnPostUserEventId = 0;
949cdf0e10cSrcweir 
950cdf0e10cSrcweir 	// create the picker component
951cdf0e10cSrcweir 	mxFileDlg = mxFileDlg.query( xFactory->createInstance( aService ) );
952cdf0e10cSrcweir 	mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg );
953cdf0e10cSrcweir 
954cdf0e10cSrcweir 	uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
955cdf0e10cSrcweir 	uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY );
956cdf0e10cSrcweir 
957cdf0e10cSrcweir 	if ( ! mxFileDlg.is() || ! xNotifier.is() )
958cdf0e10cSrcweir 	{
959cdf0e10cSrcweir 		mnError = ERRCODE_ABORT;
960cdf0e10cSrcweir 		return;
961cdf0e10cSrcweir 	}
962cdf0e10cSrcweir 
963cdf0e10cSrcweir 
964cdf0e10cSrcweir 	if ( xInit.is() )
965cdf0e10cSrcweir 	{
966cdf0e10cSrcweir 		sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
967cdf0e10cSrcweir 
968cdf0e10cSrcweir 		switch ( m_nDialogType )
969cdf0e10cSrcweir 		{
970cdf0e10cSrcweir 			case FILEOPEN_SIMPLE:
971cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
972cdf0e10cSrcweir 				break;
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 			case FILESAVE_SIMPLE:
975cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILESAVE_SIMPLE;
976cdf0e10cSrcweir 				mbIsSaveDlg = sal_True;
977cdf0e10cSrcweir 				break;
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 			case FILESAVE_AUTOEXTENSION_PASSWORD:
980cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
981cdf0e10cSrcweir 				mbHasPassword = sal_True;
982cdf0e10cSrcweir 				mbHasAutoExt = sal_True;
983cdf0e10cSrcweir 				mbIsSaveDlg = sal_True;
984cdf0e10cSrcweir 				break;
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 			case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
987cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS;
988cdf0e10cSrcweir 				mbHasPassword = sal_True;
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 				m_bHaveFilterOptions = sal_True;
991cdf0e10cSrcweir 				if( xFactory.is() )
992cdf0e10cSrcweir 				{
993cdf0e10cSrcweir 					mxFilterCFG = uno::Reference< XNameAccess >(
994cdf0e10cSrcweir 						xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
995cdf0e10cSrcweir 						UNO_QUERY );
996cdf0e10cSrcweir 				}
997cdf0e10cSrcweir 
998cdf0e10cSrcweir 				mbHasAutoExt = sal_True;
999cdf0e10cSrcweir 				mbIsSaveDlg = sal_True;
1000cdf0e10cSrcweir 				break;
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 			case FILESAVE_AUTOEXTENSION_SELECTION:
1003cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION;
1004cdf0e10cSrcweir 				mbHasAutoExt = sal_True;
1005cdf0e10cSrcweir 				mbIsSaveDlg = sal_True;
1006cdf0e10cSrcweir 				mbHasSelectionBox = sal_True;
1007cdf0e10cSrcweir 				if ( mbExport && !mxFilterCFG.is() && xFactory.is() )
1008cdf0e10cSrcweir 				{
1009cdf0e10cSrcweir 					mxFilterCFG = uno::Reference< XNameAccess >(
1010cdf0e10cSrcweir 						xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
1011cdf0e10cSrcweir 						UNO_QUERY );
1012cdf0e10cSrcweir 				}
1013cdf0e10cSrcweir 				break;
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir 			case FILESAVE_AUTOEXTENSION_TEMPLATE:
1016cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE;
1017cdf0e10cSrcweir 				mbHasAutoExt = sal_True;
1018cdf0e10cSrcweir 				mbIsSaveDlg = sal_True;
1019cdf0e10cSrcweir 				break;
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir 			case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
1022cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
1023cdf0e10cSrcweir 				mbHasPreview = sal_True;
1024cdf0e10cSrcweir 				mbHasLink = sal_True;
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir 				// aPreviewTimer
1027cdf0e10cSrcweir 				maPreViewTimer.SetTimeout( 500 );
1028cdf0e10cSrcweir 				maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
1029cdf0e10cSrcweir 				break;
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir 			case FILEOPEN_PLAY:
1032cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILEOPEN_PLAY;
1033cdf0e10cSrcweir 				break;
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 			case FILEOPEN_READONLY_VERSION:
1036cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILEOPEN_READONLY_VERSION;
1037cdf0e10cSrcweir 				mbHasVersions = sal_True;
1038cdf0e10cSrcweir 				break;
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir 			case FILEOPEN_LINK_PREVIEW:
1041cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW;
1042cdf0e10cSrcweir 				mbHasPreview = sal_True;
1043cdf0e10cSrcweir 				mbHasLink = sal_True;
1044cdf0e10cSrcweir 				// aPreviewTimer
1045cdf0e10cSrcweir 				maPreViewTimer.SetTimeout( 500 );
1046cdf0e10cSrcweir 				maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
1047cdf0e10cSrcweir 				break;
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir 			case FILESAVE_AUTOEXTENSION:
1050cdf0e10cSrcweir 				nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION;
1051cdf0e10cSrcweir 				mbHasAutoExt = sal_True;
1052cdf0e10cSrcweir 				mbIsSaveDlg = sal_True;
1053cdf0e10cSrcweir 				break;
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir 			default:
1056cdf0e10cSrcweir 				DBG_ERRORFILE( "FileDialogHelper::ctor with unknown type" );
1057cdf0e10cSrcweir 				break;
1058cdf0e10cSrcweir 		}
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir 		//Sequence < Any > aInitArguments( mbSystemPicker || !mpPreferredParentWindow ? 1 : 3 );
1063cdf0e10cSrcweir 		Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 );
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir 		// This is a hack. We currently know that the internal file picker implementation
1066cdf0e10cSrcweir 		// supports the extended arguments as specified below.
1067cdf0e10cSrcweir         // TODO:
1068cdf0e10cSrcweir 		// a) adjust the service description so that it includes the TemplateDescription and ParentWindow args
1069cdf0e10cSrcweir 		// b) adjust the implementation of the system file picker to that it recognizes it
1070cdf0e10cSrcweir 		if ( mbSystemPicker )
1071cdf0e10cSrcweir 		{
1072cdf0e10cSrcweir 			aInitArguments[0] <<= nTemplateDescription;
1073cdf0e10cSrcweir 		}
1074cdf0e10cSrcweir 		else
1075cdf0e10cSrcweir 		{
1076cdf0e10cSrcweir 			aInitArguments[0] <<= NamedValue(
1077cdf0e10cSrcweir 									::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateDescription" ) ),
1078cdf0e10cSrcweir 									makeAny( nTemplateDescription )
1079cdf0e10cSrcweir 								);
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 			::rtl::OUString sStandardDirTemp = ::rtl::OUString( sStandardDir );
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir 			aInitArguments[1] <<= NamedValue(
1084cdf0e10cSrcweir 									::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StandardDir" ) ),
1085cdf0e10cSrcweir 									makeAny( sStandardDirTemp )
1086cdf0e10cSrcweir 								);
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 			aInitArguments[2] <<= NamedValue(
1089cdf0e10cSrcweir 									::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlackList" ) ),
1090cdf0e10cSrcweir 									makeAny( rBlackList )
1091cdf0e10cSrcweir 								);
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir 			if ( mpPreferredParentWindow )
1095cdf0e10cSrcweir 				aInitArguments[3] <<= NamedValue(
1096cdf0e10cSrcweir 										::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ),
1097cdf0e10cSrcweir 										makeAny( VCLUnoHelper::GetInterface( mpPreferredParentWindow ) )
1098cdf0e10cSrcweir 									);
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir 		}
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir 		try
1104cdf0e10cSrcweir 		{
1105cdf0e10cSrcweir 			xInit->initialize( aInitArguments );
1106cdf0e10cSrcweir 		}
1107cdf0e10cSrcweir 		catch( const Exception& )
1108cdf0e10cSrcweir 		{
1109cdf0e10cSrcweir 			DBG_ERROR( "FileDialogHelper_Impl::FileDialogHelper_Impl: could not initialize the picker!" );
1110cdf0e10cSrcweir 		}
1111cdf0e10cSrcweir 	}
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir 	// set multiselection mode
1115cdf0e10cSrcweir 	if ( nFlags & SFXWB_MULTISELECTION )
1116cdf0e10cSrcweir 		mxFileDlg->setMultiSelectionMode( sal_True );
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir 	if ( mbHasLink )		// generate graphic filter only on demand
1119cdf0e10cSrcweir 		addGraphicFilter();
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir 	// Export dialog
1122cdf0e10cSrcweir 	if ( mbExport )
1123cdf0e10cSrcweir 	{
1124cdf0e10cSrcweir 		mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) ) ) );
1125cdf0e10cSrcweir 		try {
1126cdf0e10cSrcweir                 com::sun::star::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW );
1127cdf0e10cSrcweir 				xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, sal_True );
1128cdf0e10cSrcweir 		}
1129cdf0e10cSrcweir 		catch( const Exception & ) { }
1130cdf0e10cSrcweir 	}
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir 	// the "insert file" dialog needs another title
1133cdf0e10cSrcweir 	if ( mbInsert )
1134cdf0e10cSrcweir 	{
1135cdf0e10cSrcweir 		mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_INSERT ) ) ) );
1136cdf0e10cSrcweir 		uno::Reference < XFilePickerControlAccess > xExtDlg( mxFileDlg, UNO_QUERY );
1137cdf0e10cSrcweir 		if ( xExtDlg.is() )
1138cdf0e10cSrcweir 		{
1139cdf0e10cSrcweir 			try
1140cdf0e10cSrcweir 			{
1141cdf0e10cSrcweir 				xExtDlg->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK,
1142cdf0e10cSrcweir 								   OUString( String( SfxResId( STR_SFX_EXPLORERFILE_BUTTONINSERT ) ) ) );
1143cdf0e10cSrcweir 			}
1144cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
1145cdf0e10cSrcweir 		}
1146cdf0e10cSrcweir 	}
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 	// add the event listener
1149cdf0e10cSrcweir 	xNotifier->addFilePickerListener( this );
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir // ------------------------------------------------------------------------
~FileDialogHelper_Impl()1153cdf0e10cSrcweir FileDialogHelper_Impl::~FileDialogHelper_Impl()
1154cdf0e10cSrcweir {
1155cdf0e10cSrcweir 	// Remove user event if we haven't received it yet
1156cdf0e10cSrcweir 	if ( mnPostUserEventId )
1157cdf0e10cSrcweir 		Application::RemoveUserEvent( mnPostUserEventId );
1158cdf0e10cSrcweir 	mnPostUserEventId = 0;
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 	delete mpGraphicFilter;
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 	if ( mbDeleteMatcher )
1163cdf0e10cSrcweir 		delete mpMatcher;
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 	maPreViewTimer.SetTimeoutHdl( Link() );
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir 	::comphelper::disposeComponent( mxFileDlg );
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir #define nMagic -1
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir class PickerThread_Impl : public ::vos::OThread
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir 	uno::Reference < XFilePicker > mxPicker;
1175cdf0e10cSrcweir 	::vos::OMutex			maMutex;
1176cdf0e10cSrcweir 	virtual void SAL_CALL	run();
1177cdf0e10cSrcweir 	sal_Int16				mnRet;
1178cdf0e10cSrcweir public:
PickerThread_Impl(const uno::Reference<XFilePicker> & rPicker)1179cdf0e10cSrcweir 							PickerThread_Impl( const uno::Reference < XFilePicker >& rPicker )
1180cdf0e10cSrcweir 							: mxPicker( rPicker ), mnRet(nMagic) {}
1181cdf0e10cSrcweir 
GetReturnValue()1182cdf0e10cSrcweir 	sal_Int16				GetReturnValue()
1183cdf0e10cSrcweir 							{ ::vos::OGuard aGuard( maMutex ); return mnRet; }
1184cdf0e10cSrcweir 
SetReturnValue(sal_Int16 aRetValue)1185cdf0e10cSrcweir 	void					SetReturnValue( sal_Int16 aRetValue )
1186cdf0e10cSrcweir 							{ ::vos::OGuard aGuard( maMutex ); mnRet = aRetValue; }
1187cdf0e10cSrcweir };
1188cdf0e10cSrcweir 
run()1189cdf0e10cSrcweir void SAL_CALL PickerThread_Impl::run()
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir 	try
1192cdf0e10cSrcweir 	{
1193cdf0e10cSrcweir 		sal_Int16 n = mxPicker->execute();
1194cdf0e10cSrcweir 		SetReturnValue( n );
1195cdf0e10cSrcweir 	}
1196cdf0e10cSrcweir 	catch( RuntimeException& )
1197cdf0e10cSrcweir 	{
1198cdf0e10cSrcweir 		SetReturnValue( ExecutableDialogResults::CANCEL );
1199cdf0e10cSrcweir 		DBG_ERRORFILE( "RuntimeException caught" );
1200cdf0e10cSrcweir 	}
1201cdf0e10cSrcweir }
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir // ------------------------------------------------------------------------
setControlHelpIds(const sal_Int16 * _pControlId,const char ** _pHelpId)1204cdf0e10cSrcweir void FileDialogHelper_Impl::setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
1205cdf0e10cSrcweir {
1206cdf0e10cSrcweir 	DBG_ASSERT( _pControlId && _pHelpId, "FileDialogHelper_Impl::setControlHelpIds: invalid array pointers!" );
1207cdf0e10cSrcweir 	if ( !_pControlId || !_pHelpId )
1208cdf0e10cSrcweir 		return;
1209cdf0e10cSrcweir 
1210cdf0e10cSrcweir 	// forward these ids to the file picker
1211cdf0e10cSrcweir 	try
1212cdf0e10cSrcweir 	{
1213cdf0e10cSrcweir 		const ::rtl::OUString sHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( INET_HID_SCHEME ) );
1214cdf0e10cSrcweir 		// the ids for the single controls
1215cdf0e10cSrcweir 		uno::Reference< XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
1216cdf0e10cSrcweir 		if ( xControlAccess.is() )
1217cdf0e10cSrcweir 		{
1218cdf0e10cSrcweir 			while ( *_pControlId )
1219cdf0e10cSrcweir 			{
1220cdf0e10cSrcweir                 DBG_ASSERT( INetURLObject( rtl::OStringToOUString( *_pHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
1221cdf0e10cSrcweir 				::rtl::OUString sId( sHelpIdPrefix );
1222cdf0e10cSrcweir 				sId += ::rtl::OUString( *_pHelpId, strlen( *_pHelpId ), RTL_TEXTENCODING_UTF8 );
1223cdf0e10cSrcweir 				xControlAccess->setValue( *_pControlId, ControlActions::SET_HELP_URL, makeAny( sId ) );
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir 				++_pControlId; ++_pHelpId;
1226cdf0e10cSrcweir 			}
1227cdf0e10cSrcweir 		}
1228cdf0e10cSrcweir 	}
1229cdf0e10cSrcweir 	catch( const Exception& )
1230cdf0e10cSrcweir 	{
1231cdf0e10cSrcweir 		DBG_ERROR( "FileDialogHelper_Impl::setControlHelpIds: caught an exception while setting the help ids!" );
1232cdf0e10cSrcweir 	}
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir // ------------------------------------------------------------------------
IMPL_LINK(FileDialogHelper_Impl,InitControls,void *,NOTINTERESTEDIN)1236cdf0e10cSrcweir IMPL_LINK( FileDialogHelper_Impl, InitControls, void*, NOTINTERESTEDIN )
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir     (void)NOTINTERESTEDIN;
1239cdf0e10cSrcweir     mnPostUserEventId = 0;
1240cdf0e10cSrcweir 	enablePasswordBox( sal_True );
1241cdf0e10cSrcweir 	updateFilterOptionsBox( );
1242cdf0e10cSrcweir 	updateSelectionBox( );
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir     return 0L;
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir // ------------------------------------------------------------------------
preExecute()1248cdf0e10cSrcweir void FileDialogHelper_Impl::preExecute()
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir 	loadConfig( );
1251cdf0e10cSrcweir 	setDefaultValues( );
1252cdf0e10cSrcweir 	updatePreviewState( sal_False );
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir 	implInitializeFileName( );
1255cdf0e10cSrcweir 	// #106079# / 2002-12-09 / fs@openoffice.org
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir #if !(defined(MACOSX) && defined(QUARTZ)) && !defined(WNT)
1258cdf0e10cSrcweir 	// allow for dialog implementations which need to be executed before they return valid values for
1259cdf0e10cSrcweir 	// current filter and such
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 	// On Vista (at least SP1) it's the same as on MacOSX, the modal dialog won't let message pass
1262cdf0e10cSrcweir 	// through before it returns from execution
1263cdf0e10cSrcweir     mnPostUserEventId = Application::PostUserEvent( LINK( this, FileDialogHelper_Impl, InitControls ) );
1264cdf0e10cSrcweir #else
1265cdf0e10cSrcweir 	// However, the Mac OS X implementation's pickers run modally in execute and so the event doesn't
1266cdf0e10cSrcweir 	// get through in time... so we call the methods directly
1267cdf0e10cSrcweir     enablePasswordBox( sal_True );
1268cdf0e10cSrcweir 	updateFilterOptionsBox( );
1269cdf0e10cSrcweir 	updateSelectionBox( );
1270cdf0e10cSrcweir #endif
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir // ------------------------------------------------------------------------
postExecute(sal_Int16 _nResult)1274cdf0e10cSrcweir void FileDialogHelper_Impl::postExecute( sal_Int16 _nResult )
1275cdf0e10cSrcweir {
1276cdf0e10cSrcweir 	if ( ExecutableDialogResults::CANCEL != _nResult )
1277cdf0e10cSrcweir 		saveConfig();
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir // ------------------------------------------------------------------------
implInitializeFileName()1281cdf0e10cSrcweir void FileDialogHelper_Impl::implInitializeFileName( )
1282cdf0e10cSrcweir {
1283cdf0e10cSrcweir 	if ( maFileName.getLength() )
1284cdf0e10cSrcweir 	{
1285cdf0e10cSrcweir 		INetURLObject aObj( maPath );
1286cdf0e10cSrcweir 		aObj.Append( maFileName );
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir 		// in case we're operating as save dialog, and "auto extension" is checked,
1289cdf0e10cSrcweir 		// cut the extension from the name
1290cdf0e10cSrcweir 		// #106079# / 2002-12-09 / fs@openoffice.org
1291cdf0e10cSrcweir 		if ( mbIsSaveDlg && mbHasAutoExt )
1292cdf0e10cSrcweir 		{
1293cdf0e10cSrcweir 			try
1294cdf0e10cSrcweir 			{
1295cdf0e10cSrcweir 				sal_Bool bAutoExtChecked = sal_False;
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir 				uno::Reference < XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
1298cdf0e10cSrcweir 				if	(	xControlAccess.is()
1299cdf0e10cSrcweir 					&&	(	xControlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 )
1300cdf0e10cSrcweir 						>>=	bAutoExtChecked
1301cdf0e10cSrcweir 						)
1302cdf0e10cSrcweir 					)
1303cdf0e10cSrcweir 				{
1304cdf0e10cSrcweir 					if ( bAutoExtChecked )
1305cdf0e10cSrcweir 					{	// cut the extension
1306cdf0e10cSrcweir 						aObj.removeExtension( );
1307cdf0e10cSrcweir 						mxFileDlg->setDefaultName( aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
1308cdf0e10cSrcweir 					}
1309cdf0e10cSrcweir 				}
1310cdf0e10cSrcweir 			}
1311cdf0e10cSrcweir 			catch( const Exception& )
1312cdf0e10cSrcweir 			{
1313cdf0e10cSrcweir 				DBG_ERROR( "FileDialogHelper_Impl::implInitializeFileName: could not ask for the auto-extension current-value!" );
1314cdf0e10cSrcweir 			}
1315cdf0e10cSrcweir 		}
1316cdf0e10cSrcweir 	}
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir // ------------------------------------------------------------------------
implDoExecute()1320cdf0e10cSrcweir sal_Int16 FileDialogHelper_Impl::implDoExecute()
1321cdf0e10cSrcweir {
1322cdf0e10cSrcweir 	preExecute();
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir 	sal_Int16 nRet = ExecutableDialogResults::CANCEL;
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir //On MacOSX the native file picker has to run in the primordial thread because of drawing issues
1327cdf0e10cSrcweir //On Linux the native gtk file picker, when backed by gnome-vfs2, needs to be run in the same
1328cdf0e10cSrcweir //primordial thread as the ucb gnome-vfs2 provider was initialized in.
1329cdf0e10cSrcweir /*
1330cdf0e10cSrcweir #ifdef WNT
1331cdf0e10cSrcweir 	if ( mbSystemPicker )
1332cdf0e10cSrcweir 	{
1333cdf0e10cSrcweir 		PickerThread_Impl* pThread = new PickerThread_Impl( mxFileDlg );
1334cdf0e10cSrcweir 		pThread->create();
1335cdf0e10cSrcweir 		while ( pThread->GetReturnValue() == nMagic )
1336cdf0e10cSrcweir 			Application::Yield();
1337cdf0e10cSrcweir 		pThread->join();
1338cdf0e10cSrcweir 		nRet = pThread->GetReturnValue();
1339cdf0e10cSrcweir 		delete pThread;
1340cdf0e10cSrcweir 	}
1341cdf0e10cSrcweir 	else
1342cdf0e10cSrcweir #endif
1343cdf0e10cSrcweir */
1344cdf0e10cSrcweir 	{
1345cdf0e10cSrcweir 		try
1346cdf0e10cSrcweir 		{
1347cdf0e10cSrcweir #ifdef WNT
1348cdf0e10cSrcweir             if ( mbSystemPicker )
1349cdf0e10cSrcweir             {
1350cdf0e10cSrcweir                 OReleaseSolarMutex aSolarMutex;
1351cdf0e10cSrcweir                 nRet = mxFileDlg->execute();
1352cdf0e10cSrcweir             }
1353cdf0e10cSrcweir             else
1354cdf0e10cSrcweir #endif
1355cdf0e10cSrcweir             nRet = mxFileDlg->execute();
1356cdf0e10cSrcweir 		}
1357cdf0e10cSrcweir 		catch( const Exception& )
1358cdf0e10cSrcweir 		{
1359cdf0e10cSrcweir 			DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
1360cdf0e10cSrcweir 		}
1361cdf0e10cSrcweir 	}
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir 	postExecute( nRet );
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir 	return nRet;
1366cdf0e10cSrcweir }
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir // ------------------------------------------------------------------------
implStartExecute()1369cdf0e10cSrcweir void FileDialogHelper_Impl::implStartExecute()
1370cdf0e10cSrcweir {
1371cdf0e10cSrcweir     DBG_ASSERT( mxFileDlg.is(), "invalid file dialog" );
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir     preExecute();
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir     if ( mbSystemPicker )
1376cdf0e10cSrcweir     {
1377cdf0e10cSrcweir     }
1378cdf0e10cSrcweir     else
1379cdf0e10cSrcweir     {
1380cdf0e10cSrcweir         try
1381cdf0e10cSrcweir         {
1382cdf0e10cSrcweir             uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( mxFileDlg, UNO_QUERY );
1383cdf0e10cSrcweir             if ( xAsyncDlg.is() )
1384cdf0e10cSrcweir                 xAsyncDlg->startExecuteModal( this );
1385cdf0e10cSrcweir         }
1386cdf0e10cSrcweir         catch( const Exception& )
1387cdf0e10cSrcweir         {
1388cdf0e10cSrcweir             DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
1389cdf0e10cSrcweir         }
1390cdf0e10cSrcweir     }
1391cdf0e10cSrcweir }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir // ------------------------------------------------------------------------
implEnsureURLExtension(const String & sURL,const String &)1394cdf0e10cSrcweir String FileDialogHelper_Impl::implEnsureURLExtension(const String& sURL,
1395cdf0e10cSrcweir 													 const String& /*sExtension*/)
1396cdf0e10cSrcweir {
1397cdf0e10cSrcweir     return sURL;
1398cdf0e10cSrcweir     /*
1399cdf0e10cSrcweir 	// This feature must be active for file save/export only !
1400cdf0e10cSrcweir 	if (
1401cdf0e10cSrcweir 		(! mbIsSaveDlg) &&
1402cdf0e10cSrcweir 		(! mbExport   )
1403cdf0e10cSrcweir 		)
1404cdf0e10cSrcweir 		return sURL;
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir 	// no extension available (because "ALL *.*" was selected) ?
1407cdf0e10cSrcweir 	// Nod idea what else should happen here .-)
1408cdf0e10cSrcweir 	if (sExtension.Len() < 1)
1409cdf0e10cSrcweir 		return sURL;
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir 	// Some FilePicker implementations already add the right extension ...
1412cdf0e10cSrcweir 	// or might be the user used the right one already ...
1413cdf0e10cSrcweir 	// Dont create duplicate extension.
1414cdf0e10cSrcweir 	INetURLObject aURL(sURL);
1415cdf0e10cSrcweir 	if (aURL.getExtension().equals(sExtension))
1416cdf0e10cSrcweir 		return sURL;
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir 	// Ignore any other extension set by the user.
1419cdf0e10cSrcweir 	// Make sure suitable extension is used always.
1420cdf0e10cSrcweir 	// e.g. "test.bla.odt" for "ODT"
1421cdf0e10cSrcweir 	::rtl::OUStringBuffer sNewURL(256);
1422cdf0e10cSrcweir 	sNewURL.append     (sURL      );
1423cdf0e10cSrcweir 	sNewURL.appendAscii("."       );
1424cdf0e10cSrcweir 	sNewURL.append     (sExtension);
1425cdf0e10cSrcweir 	return sNewURL.makeStringAndClear();
1426cdf0e10cSrcweir     */
1427cdf0e10cSrcweir }
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir // ------------------------------------------------------------------------
lcl_saveLastURLs(SvStringsDtor * & rpURLList,::comphelper::SequenceAsVector<::rtl::OUString> & lLastURLs)1430cdf0e10cSrcweir void lcl_saveLastURLs(SvStringsDtor*&                                    rpURLList ,
1431cdf0e10cSrcweir                       ::comphelper::SequenceAsVector< ::rtl::OUString >& lLastURLs )
1432cdf0e10cSrcweir {
1433cdf0e10cSrcweir     lLastURLs.clear();
1434cdf0e10cSrcweir     sal_uInt16 c = rpURLList->Count();
1435cdf0e10cSrcweir     sal_uInt16 i = 0;
1436cdf0e10cSrcweir     for (i=0; i<c; ++i)
1437cdf0e10cSrcweir         lLastURLs.push_back(*(rpURLList->GetObject(i)));
1438cdf0e10cSrcweir }
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir // ------------------------------------------------------------------------
implGetAndCacheFiles(const uno::Reference<XInterface> & xPicker,SvStringsDtor * & rpURLList,const SfxFilter * pFilter)1441cdf0e10cSrcweir void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker  ,
1442cdf0e10cSrcweir 													   SvStringsDtor*&               rpURLList,
1443cdf0e10cSrcweir 												 const SfxFilter*                    pFilter  )
1444cdf0e10cSrcweir {
1445cdf0e10cSrcweir     rpURLList = NULL;
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir 	String sExtension;
1448cdf0e10cSrcweir 	if (pFilter)
1449cdf0e10cSrcweir 	{
1450cdf0e10cSrcweir 		sExtension = pFilter->GetDefaultExtension ();
1451cdf0e10cSrcweir 		sExtension.EraseAllChars( '*' );
1452cdf0e10cSrcweir 		sExtension.EraseAllChars( '.' );
1453cdf0e10cSrcweir 	}
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir     // a) the new way (optional!)
1456cdf0e10cSrcweir     uno::Reference< XFilePicker2 > xPickNew(xPicker, UNO_QUERY);
1457cdf0e10cSrcweir     if (xPickNew.is())
1458cdf0e10cSrcweir     {
1459cdf0e10cSrcweir                              rpURLList = new SvStringsDtor;
1460cdf0e10cSrcweir         Sequence< OUString > lFiles    = xPickNew->getSelectedFiles();
1461cdf0e10cSrcweir         ::sal_Int32          nFiles    = lFiles.getLength();
1462cdf0e10cSrcweir         for (::sal_Int32 i = 0; i < nFiles; i++)
1463cdf0e10cSrcweir         {
1464cdf0e10cSrcweir 			String* pURL = new String(implEnsureURLExtension(lFiles[i], sExtension));
1465cdf0e10cSrcweir             rpURLList->Insert( pURL, rpURLList->Count() );
1466cdf0e10cSrcweir         }
1467cdf0e10cSrcweir     }
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir     // b) the olde way ... non optional.
1470cdf0e10cSrcweir     else
1471cdf0e10cSrcweir     {
1472cdf0e10cSrcweir         uno::Reference< XFilePicker > xPickOld(xPicker, UNO_QUERY_THROW);
1473cdf0e10cSrcweir         Sequence< OUString > lFiles = xPickOld->getFiles();
1474cdf0e10cSrcweir         ::sal_Int32          nFiles = lFiles.getLength();
1475cdf0e10cSrcweir         if ( nFiles == 1 )
1476cdf0e10cSrcweir         {
1477cdf0e10cSrcweir                     rpURLList = new SvStringsDtor;
1478cdf0e10cSrcweir 			String* pURL      = new String(implEnsureURLExtension(lFiles[0], sExtension));
1479cdf0e10cSrcweir             rpURLList->Insert( pURL, 0 );
1480cdf0e10cSrcweir         }
1481cdf0e10cSrcweir         else
1482cdf0e10cSrcweir         if ( nFiles > 1 )
1483cdf0e10cSrcweir         {
1484cdf0e10cSrcweir             rpURLList = new SvStringsDtor;
1485cdf0e10cSrcweir 
1486cdf0e10cSrcweir             INetURLObject aPath( lFiles[0] );
1487cdf0e10cSrcweir             aPath.setFinalSlash();
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir             for (::sal_Int32 i = 1; i < nFiles; i++)
1490cdf0e10cSrcweir             {
1491cdf0e10cSrcweir                 if (i == 1)
1492cdf0e10cSrcweir                     aPath.Append( lFiles[i] );
1493cdf0e10cSrcweir                 else
1494cdf0e10cSrcweir                     aPath.setName( lFiles[i] );
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir                 String* pURL = new String(implEnsureURLExtension(aPath.GetMainURL( INetURLObject::NO_DECODE ), sExtension) );
1497cdf0e10cSrcweir                 rpURLList->Insert( pURL, rpURLList->Count() );
1498cdf0e10cSrcweir             }
1499cdf0e10cSrcweir         }
1500cdf0e10cSrcweir     }
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir 	lcl_saveLastURLs(rpURLList, mlLastURLs);
1503cdf0e10cSrcweir }
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir // ------------------------------------------------------------------------
execute(SvStringsDtor * & rpURLList,SfxItemSet * & rpSet,String & rFilter)1506cdf0e10cSrcweir ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
1507cdf0e10cSrcweir 										SfxItemSet *&	rpSet,
1508cdf0e10cSrcweir 										String& 		rFilter )
1509cdf0e10cSrcweir {
1510cdf0e10cSrcweir     // rFilter is a pure output parameter, it shouldn't be used for anything else
1511cdf0e10cSrcweir     // changing this would surely break code
1512cdf0e10cSrcweir     // rpSet is in/out parameter, usually just a media-descriptor that can be changed by dialog
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir 	uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	// retrieves parameters from rpSet
1517cdf0e10cSrcweir 	// for now only Password is used
1518cdf0e10cSrcweir 	if ( rpSet )
1519cdf0e10cSrcweir 	{
1520cdf0e10cSrcweir 		// check password checkbox if the document had password before
1521cdf0e10cSrcweir 		if( mbHasPassword )
1522cdf0e10cSrcweir 		{
1523cdf0e10cSrcweir 			SFX_ITEMSET_ARG( rpSet, pPassItem, SfxBoolItem, SID_PASSWORDINTERACTION, sal_False );
1524cdf0e10cSrcweir 			mbPwdCheckBoxState = ( pPassItem != NULL && pPassItem->GetValue() );
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir             // in case the document has password to modify, the dialog should be shown
1527cdf0e10cSrcweir 			SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
1528cdf0e10cSrcweir             mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue().hasValue() );
1529cdf0e10cSrcweir 		}
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir 		SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False );
1532cdf0e10cSrcweir 		if ( pSelectItem )
1533cdf0e10cSrcweir 			mbSelection = pSelectItem->GetValue();
1534cdf0e10cSrcweir 		else
1535cdf0e10cSrcweir 			mbSelectionEnabled = sal_False;
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir 		// the password will be set in case user decide so
1538cdf0e10cSrcweir 		rpSet->ClearItem( SID_PASSWORDINTERACTION );
1539cdf0e10cSrcweir 		rpSet->ClearItem( SID_PASSWORD );
1540cdf0e10cSrcweir 		rpSet->ClearItem( SID_ENCRYPTIONDATA );
1541cdf0e10cSrcweir         rpSet->ClearItem( SID_RECOMMENDREADONLY );
1542cdf0e10cSrcweir         rpSet->ClearItem( SID_MODIFYPASSWORDINFO );
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir 	}
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir 	if ( mbHasPassword && !mbPwdCheckBoxState )
1547cdf0e10cSrcweir 	{
1548cdf0e10cSrcweir 		SvtSecurityOptions aSecOpt;
1549cdf0e10cSrcweir 		mbPwdCheckBoxState = (
1550cdf0e10cSrcweir 			aSecOpt.IsOptionSet( SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD ) );
1551cdf0e10cSrcweir 	}
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir 	rpURLList = NULL;
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir 	if ( ! mxFileDlg.is() )
1556cdf0e10cSrcweir 		return ERRCODE_ABORT;
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir 	if ( ExecutableDialogResults::CANCEL != implDoExecute() )
1559cdf0e10cSrcweir 	{
1560cdf0e10cSrcweir 		// create an itemset if there is no
1561cdf0e10cSrcweir 		if( !rpSet )
1562cdf0e10cSrcweir 			rpSet = new SfxAllItemSet( SFX_APP()->GetPool() );
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir         // the item should remain only if it was set by the dialog
1565cdf0e10cSrcweir         rpSet->ClearItem( SID_SELECTION );
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir 		if( mbExport && mbHasSelectionBox )
1568cdf0e10cSrcweir 		{
1569cdf0e10cSrcweir 			try
1570cdf0e10cSrcweir 			{
1571cdf0e10cSrcweir 				Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
1572cdf0e10cSrcweir 				sal_Bool bSelection = sal_False;
1573cdf0e10cSrcweir 				if ( aValue >>= bSelection )
1574cdf0e10cSrcweir 					rpSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
1575cdf0e10cSrcweir 			}
1576cdf0e10cSrcweir 			catch( IllegalArgumentException )
1577cdf0e10cSrcweir 			{
1578cdf0e10cSrcweir 				DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
1579cdf0e10cSrcweir 			}
1580cdf0e10cSrcweir 		}
1581cdf0e10cSrcweir 
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir 		// set the read-only flag. When inserting a file, this flag is always set
1584cdf0e10cSrcweir 		if ( mbInsert )
1585cdf0e10cSrcweir 			rpSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
1586cdf0e10cSrcweir 		else
1587cdf0e10cSrcweir 		{
1588cdf0e10cSrcweir 			if ( ( FILEOPEN_READONLY_VERSION == m_nDialogType ) && xCtrlAccess.is() )
1589cdf0e10cSrcweir 			{
1590cdf0e10cSrcweir 				try
1591cdf0e10cSrcweir 				{
1592cdf0e10cSrcweir 					Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
1593cdf0e10cSrcweir 					sal_Bool bReadOnly = sal_False;
1594cdf0e10cSrcweir 					if ( ( aValue >>= bReadOnly ) && bReadOnly )
1595cdf0e10cSrcweir 						rpSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
1596cdf0e10cSrcweir 				}
1597cdf0e10cSrcweir 				catch( IllegalArgumentException )
1598cdf0e10cSrcweir 				{
1599cdf0e10cSrcweir 					DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
1600cdf0e10cSrcweir 				}
1601cdf0e10cSrcweir 			}
1602cdf0e10cSrcweir 		}
1603cdf0e10cSrcweir 		if ( mbHasVersions && xCtrlAccess.is() )
1604cdf0e10cSrcweir 		{
1605cdf0e10cSrcweir 			try
1606cdf0e10cSrcweir 			{
1607cdf0e10cSrcweir 				Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
1608cdf0e10cSrcweir 													ControlActions::GET_SELECTED_ITEM_INDEX );
1609cdf0e10cSrcweir 				sal_Int32 nVersion = 0;
1610cdf0e10cSrcweir 				if ( ( aValue >>= nVersion ) && nVersion > 0 )
1611cdf0e10cSrcweir 					// open a special version; 0 == current version
1612cdf0e10cSrcweir 					rpSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) );
1613cdf0e10cSrcweir 			}
1614cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
1615cdf0e10cSrcweir 		}
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir 		// set the filter
1618cdf0e10cSrcweir 		getRealFilter( rFilter );
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir         const SfxFilter* pCurrentFilter = getCurentSfxFilter();
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir 		// fill the rpURLList
1623cdf0e10cSrcweir 		implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter );
1624cdf0e10cSrcweir 		if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL )
1625cdf0e10cSrcweir 			return ERRCODE_ABORT;
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir 		// check, wether or not we have to display a password box
1628cdf0e10cSrcweir 		if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() )
1629cdf0e10cSrcweir 		{
1630cdf0e10cSrcweir 			try
1631cdf0e10cSrcweir 			{
1632cdf0e10cSrcweir 				Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
1633cdf0e10cSrcweir 				sal_Bool bPassWord = sal_False;
1634cdf0e10cSrcweir 				if ( ( aValue >>= bPassWord ) && bPassWord )
1635cdf0e10cSrcweir 				{
1636cdf0e10cSrcweir 					// ask for a password
1637cdf0e10cSrcweir                     uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir                     if( xInteractionHandler.is() )
1640cdf0e10cSrcweir                     {
1641cdf0e10cSrcweir                         // TODO: need a save way to distinguish MS filters from other filters
1642cdf0e10cSrcweir                         // for now MS-filters are the only alien filters that support encryption
1643cdf0e10cSrcweir                         sal_Bool bMSType = !pCurrentFilter->IsOwnFormat();
1644cdf0e10cSrcweir                         ::comphelper::DocPasswordRequestType eType = bMSType ?
1645cdf0e10cSrcweir                             ::comphelper::DocPasswordRequestType_MS :
1646cdf0e10cSrcweir                             ::comphelper::DocPasswordRequestType_STANDARD;
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir                         ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) );
1649cdf0e10cSrcweir 
1650cdf0e10cSrcweir                         uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
1651cdf0e10cSrcweir                         xInteractionHandler->handle( rRequest );
1652cdf0e10cSrcweir                         if ( pPasswordRequest->isPassword() )
1653cdf0e10cSrcweir                         {
1654cdf0e10cSrcweir                             if ( pPasswordRequest->getPassword().getLength() )
1655cdf0e10cSrcweir                             {
1656cdf0e10cSrcweir                                 // TODO/LATER: The filters should show the password dialog themself in future
1657cdf0e10cSrcweir                                 if ( bMSType )
1658cdf0e10cSrcweir                                 {
1659cdf0e10cSrcweir                                     // all the current MS-filters use MSCodec_Std97 implementation
1660cdf0e10cSrcweir                                     uno::Sequence< sal_Int8 > aUniqueID = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
1661cdf0e10cSrcweir                                     uno::Sequence< sal_Int8 > aEncryptionKey = ::comphelper::DocPasswordHelper::GenerateStd97Key( pPasswordRequest->getPassword(), aUniqueID );
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir                                     if ( aEncryptionKey.getLength() )
1664cdf0e10cSrcweir                                     {
1665cdf0e10cSrcweir                                         ::comphelper::SequenceAsHashMap aHashData;
1666cdf0e10cSrcweir                                         aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97EncryptionKey" ) ) ] <<= aEncryptionKey;
1667cdf0e10cSrcweir                                         aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97UniqueID" ) ) ] <<= aUniqueID;
1668cdf0e10cSrcweir 
1669cdf0e10cSrcweir                                         rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aHashData.getAsConstNamedValueList() ) ) );
1670cdf0e10cSrcweir                                     }
1671cdf0e10cSrcweir                                     else
1672cdf0e10cSrcweir                                         return ERRCODE_IO_NOTSUPPORTED;
1673cdf0e10cSrcweir                                 }
1674cdf0e10cSrcweir                                 else
1675cdf0e10cSrcweir                                 {
1676cdf0e10cSrcweir                                     rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreatePackageEncryptionData( pPasswordRequest->getPassword() ) ) ) );
1677cdf0e10cSrcweir                                 }
1678cdf0e10cSrcweir                             }
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir                             if ( pPasswordRequest->getRecommendReadOnly() )
1681cdf0e10cSrcweir                                 rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir                             if ( bMSType )
1684cdf0e10cSrcweir                             {
1685cdf0e10cSrcweir                                 // the empty password has 0 as Hash
1686cdf0e10cSrcweir                                 sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) );
1687cdf0e10cSrcweir                                 if ( nHash )
1688cdf0e10cSrcweir                                     rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) );
1689cdf0e10cSrcweir                             }
1690cdf0e10cSrcweir                             else
1691cdf0e10cSrcweir                             {
1692cdf0e10cSrcweir                                 uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() );
1693cdf0e10cSrcweir                                 if ( aModifyPasswordInfo.getLength() )
1694cdf0e10cSrcweir                                     rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) );
1695cdf0e10cSrcweir                             }
1696cdf0e10cSrcweir                         }
1697cdf0e10cSrcweir                         else
1698cdf0e10cSrcweir                             return ERRCODE_ABORT;
1699cdf0e10cSrcweir                     }
1700cdf0e10cSrcweir 				}
1701cdf0e10cSrcweir 			}
1702cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
1703cdf0e10cSrcweir 		}
1704cdf0e10cSrcweir 
1705cdf0e10cSrcweir         SaveLastUsedFilter();
1706cdf0e10cSrcweir         return ERRCODE_NONE;
1707cdf0e10cSrcweir 	}
1708cdf0e10cSrcweir 	else
1709cdf0e10cSrcweir 		return ERRCODE_ABORT;
1710cdf0e10cSrcweir }
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir // ------------------------------------------------------------------------
execute()1713cdf0e10cSrcweir ErrCode FileDialogHelper_Impl::execute()
1714cdf0e10cSrcweir {
1715cdf0e10cSrcweir 	if ( ! mxFileDlg.is() )
1716cdf0e10cSrcweir 		return ERRCODE_ABORT;
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir 	sal_Int16 nRet = implDoExecute();
1719cdf0e10cSrcweir 
1720cdf0e10cSrcweir 	maPath = mxFileDlg->getDisplayDirectory();
1721cdf0e10cSrcweir 
1722cdf0e10cSrcweir 	if ( ExecutableDialogResults::CANCEL == nRet )
1723cdf0e10cSrcweir 		return ERRCODE_ABORT;
1724cdf0e10cSrcweir 	else
1725cdf0e10cSrcweir 	{
1726cdf0e10cSrcweir 		return ERRCODE_NONE;
1727cdf0e10cSrcweir 	}
1728cdf0e10cSrcweir }
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir // ------------------------------------------------------------------------
getPath() const1731cdf0e10cSrcweir OUString FileDialogHelper_Impl::getPath() const
1732cdf0e10cSrcweir {
1733cdf0e10cSrcweir 	OUString aPath;
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir 	if ( mxFileDlg.is() )
1736cdf0e10cSrcweir 		aPath = mxFileDlg->getDisplayDirectory();
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir 	if ( !aPath.getLength() )
1739cdf0e10cSrcweir 		aPath = maPath;
1740cdf0e10cSrcweir 
1741cdf0e10cSrcweir 	return aPath;
1742cdf0e10cSrcweir }
1743cdf0e10cSrcweir 
1744cdf0e10cSrcweir // ------------------------------------------------------------------------
getFilter() const1745cdf0e10cSrcweir OUString FileDialogHelper_Impl::getFilter() const
1746cdf0e10cSrcweir {
1747cdf0e10cSrcweir 	String aFilter = getCurrentFilterUIName();
1748cdf0e10cSrcweir 
1749cdf0e10cSrcweir 	if( !aFilter.Len() )
1750cdf0e10cSrcweir 		aFilter = maCurFilter;
1751cdf0e10cSrcweir 
1752cdf0e10cSrcweir 	return aFilter;
1753cdf0e10cSrcweir }
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir // ------------------------------------------------------------------------
getRealFilter(String & _rFilter) const1756cdf0e10cSrcweir void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
1757cdf0e10cSrcweir {
1758cdf0e10cSrcweir 	_rFilter = getCurrentFilterUIName();
1759cdf0e10cSrcweir 
1760cdf0e10cSrcweir 	if ( !_rFilter.Len() )
1761cdf0e10cSrcweir 		_rFilter = maCurFilter;
1762cdf0e10cSrcweir 
1763cdf0e10cSrcweir 	if ( _rFilter.Len() && mpMatcher )
1764cdf0e10cSrcweir 	{
1765cdf0e10cSrcweir 		const SfxFilter* pFilter =
1766cdf0e10cSrcweir 			mpMatcher->GetFilter4UIName( _rFilter, m_nMustFlags, m_nDontFlags );
1767cdf0e10cSrcweir 		_rFilter = pFilter ? pFilter->GetFilterName() : _rFilter.Erase();
1768cdf0e10cSrcweir 	}
1769cdf0e10cSrcweir }
1770cdf0e10cSrcweir 
1771cdf0e10cSrcweir // ------------------------------------------------------------------------
displayFolder(const::rtl::OUString & _rPath)1772cdf0e10cSrcweir void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
1773cdf0e10cSrcweir {
1774cdf0e10cSrcweir 	if ( ! _rPath.getLength() )
1775cdf0e10cSrcweir 		// nothing to do
1776cdf0e10cSrcweir 		return;
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir 	/*
1779cdf0e10cSrcweir 	if ( !::utl::UCBContentHelper::IsFolder( _rPath ) )
1780cdf0e10cSrcweir 		// only valid folders accepted here
1781cdf0e10cSrcweir 		return;
1782cdf0e10cSrcweir 	*/
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir 	maPath = _rPath;
1785cdf0e10cSrcweir 	if ( mxFileDlg.is() )
1786cdf0e10cSrcweir 	{
1787cdf0e10cSrcweir 		try
1788cdf0e10cSrcweir 		{
1789cdf0e10cSrcweir 			mxFileDlg->setDisplayDirectory( maPath );
1790cdf0e10cSrcweir 		}
1791cdf0e10cSrcweir 		catch( const IllegalArgumentException& )
1792cdf0e10cSrcweir 		{
1793cdf0e10cSrcweir 			DBG_ERROR( "FileDialogHelper_Impl::displayFolder: caught an exception!" );
1794cdf0e10cSrcweir 		}
1795cdf0e10cSrcweir 	}
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir // ------------------------------------------------------------------------
setFileName(const::rtl::OUString & _rFile)1799cdf0e10cSrcweir void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile )
1800cdf0e10cSrcweir {
1801cdf0e10cSrcweir 	maFileName = _rFile;
1802cdf0e10cSrcweir 	if ( mxFileDlg.is() )
1803cdf0e10cSrcweir 	{
1804cdf0e10cSrcweir 		try
1805cdf0e10cSrcweir 		{
1806cdf0e10cSrcweir 			mxFileDlg->setDefaultName( maFileName );
1807cdf0e10cSrcweir 		}
1808cdf0e10cSrcweir 		catch( const IllegalArgumentException& )
1809cdf0e10cSrcweir 		{
1810cdf0e10cSrcweir 			DBG_ERROR( "FileDialogHelper_Impl::setFileName: caught an exception!" );
1811cdf0e10cSrcweir 		}
1812cdf0e10cSrcweir 	}
1813cdf0e10cSrcweir }
1814cdf0e10cSrcweir 
1815cdf0e10cSrcweir // ------------------------------------------------------------------------
setFilter(const OUString & rFilter)1816cdf0e10cSrcweir void FileDialogHelper_Impl::setFilter( const OUString& rFilter )
1817cdf0e10cSrcweir {
1818cdf0e10cSrcweir 	DBG_ASSERT( rFilter.indexOf(':') == -1, "Old filter name used!");
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir 	maCurFilter = rFilter;
1821cdf0e10cSrcweir 
1822cdf0e10cSrcweir 	if ( rFilter.getLength() && mpMatcher )
1823cdf0e10cSrcweir 	{
1824cdf0e10cSrcweir 		const SfxFilter* pFilter = mpMatcher->GetFilter4FilterName(
1825cdf0e10cSrcweir 										rFilter, m_nMustFlags, m_nDontFlags );
1826cdf0e10cSrcweir 		if ( pFilter )
1827cdf0e10cSrcweir 			maCurFilter = pFilter->GetUIName();
1828cdf0e10cSrcweir 	}
1829cdf0e10cSrcweir 
1830cdf0e10cSrcweir 	uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1831cdf0e10cSrcweir 
1832cdf0e10cSrcweir 	if ( maCurFilter.getLength() && xFltMgr.is() )
1833cdf0e10cSrcweir 	{
1834cdf0e10cSrcweir 		try
1835cdf0e10cSrcweir 		{
1836cdf0e10cSrcweir 			xFltMgr->setCurrentFilter( maCurFilter );
1837cdf0e10cSrcweir 		}
1838cdf0e10cSrcweir 		catch( IllegalArgumentException ){}
1839cdf0e10cSrcweir 	}
1840cdf0e10cSrcweir }
1841cdf0e10cSrcweir 
1842cdf0e10cSrcweir // ------------------------------------------------------------------------
createMatcher(const String & rFactory)1843cdf0e10cSrcweir void FileDialogHelper_Impl::createMatcher( const String& rFactory )
1844cdf0e10cSrcweir {
1845cdf0e10cSrcweir 	mpMatcher = new SfxFilterMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
1846cdf0e10cSrcweir 	mbDeleteMatcher = sal_True;
1847cdf0e10cSrcweir }
1848cdf0e10cSrcweir 
1849cdf0e10cSrcweir // ------------------------------------------------------------------------
addFilters(sal_Int64 nFlags,const String & rFactory,SfxFilterFlags nMust,SfxFilterFlags nDont)1850cdf0e10cSrcweir void FileDialogHelper_Impl::addFilters( sal_Int64 nFlags,
1851cdf0e10cSrcweir 										const String& rFactory,
1852cdf0e10cSrcweir 										SfxFilterFlags nMust,
1853cdf0e10cSrcweir 										SfxFilterFlags nDont )
1854cdf0e10cSrcweir {
1855cdf0e10cSrcweir 	uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1856cdf0e10cSrcweir 
1857cdf0e10cSrcweir 	if ( ! xFltMgr.is() )
1858cdf0e10cSrcweir 		return;
1859cdf0e10cSrcweir 
1860cdf0e10cSrcweir     // we still need a matcher to convert UI names to filter names
1861cdf0e10cSrcweir     if ( !rFactory.Len() )
1862cdf0e10cSrcweir     {
1863cdf0e10cSrcweir         SfxApplication *pSfxApp = SFX_APP();
1864cdf0e10cSrcweir         mpMatcher = &pSfxApp->GetFilterMatcher();
1865cdf0e10cSrcweir         mbDeleteMatcher = sal_False;
1866cdf0e10cSrcweir     }
1867cdf0e10cSrcweir     else
1868cdf0e10cSrcweir     {
1869cdf0e10cSrcweir         mpMatcher = new SfxFilterMatcher( rFactory );
1870cdf0e10cSrcweir         mbDeleteMatcher = sal_True;
1871cdf0e10cSrcweir     }
1872cdf0e10cSrcweir 
1873cdf0e10cSrcweir     uno::Reference< XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
1874cdf0e10cSrcweir     uno::Reference< XContainerQuery > xFilterCont(
1875cdf0e10cSrcweir         xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory")),
1876cdf0e10cSrcweir         UNO_QUERY);
1877cdf0e10cSrcweir     if ( ! xFilterCont.is() )
1878cdf0e10cSrcweir         return;
1879cdf0e10cSrcweir 
1880cdf0e10cSrcweir 	m_nMustFlags |= nMust;
1881cdf0e10cSrcweir 	m_nDontFlags |= nDont;
1882cdf0e10cSrcweir 
1883cdf0e10cSrcweir 	// create the list of filters
1884cdf0e10cSrcweir     ::rtl::OUStringBuffer sQuery(256);
1885cdf0e10cSrcweir     sQuery.appendAscii("getSortedFilterList()");
1886cdf0e10cSrcweir     sQuery.appendAscii(":module="										);
1887cdf0e10cSrcweir     sQuery.append     (rFactory											); // use long name here !
1888cdf0e10cSrcweir     sQuery.appendAscii(":iflags="                                       );
1889cdf0e10cSrcweir     sQuery.append     (::rtl::OUString::valueOf((sal_Int32)m_nMustFlags));
1890cdf0e10cSrcweir     sQuery.appendAscii(":eflags="                                       );
1891cdf0e10cSrcweir     sQuery.append     (::rtl::OUString::valueOf((sal_Int32)m_nDontFlags));
1892cdf0e10cSrcweir 
1893cdf0e10cSrcweir     uno::Reference< XEnumeration > xResult;
1894cdf0e10cSrcweir     try
1895cdf0e10cSrcweir     {
1896cdf0e10cSrcweir         xResult = xFilterCont->createSubSetEnumerationByQuery(sQuery.makeStringAndClear());
1897cdf0e10cSrcweir     }
1898cdf0e10cSrcweir     catch( uno::Exception& )
1899cdf0e10cSrcweir     {
1900cdf0e10cSrcweir         DBG_ERRORFILE( "Could not get filters from the configuration!" );
1901cdf0e10cSrcweir     }
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir     TSortedFilterList         aIter   (xResult);
1904cdf0e10cSrcweir 
1905cdf0e10cSrcweir     // no matcher any longer used ...
1906cdf0e10cSrcweir 	mbDeleteMatcher = sal_False;
1907cdf0e10cSrcweir 
1908cdf0e10cSrcweir 	// append the filters
1909cdf0e10cSrcweir 	::rtl::OUString sFirstFilter;
1910cdf0e10cSrcweir 	if ( WB_OPEN == ( nFlags & WB_OPEN ) )
1911cdf0e10cSrcweir 		::sfx2::appendFiltersForOpen( aIter, xFltMgr, sFirstFilter, *this );
1912cdf0e10cSrcweir 	else if ( mbExport )
1913cdf0e10cSrcweir 		::sfx2::appendExportFilters( aIter, xFltMgr, sFirstFilter, *this );
1914cdf0e10cSrcweir 	else
1915cdf0e10cSrcweir 		::sfx2::appendFiltersForSave( aIter, xFltMgr, sFirstFilter, *this, rFactory );
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir 	// set our initial selected filter (if we do not already have one)
1918cdf0e10cSrcweir 	if ( !maSelectFilter.getLength() )
1919cdf0e10cSrcweir 		maSelectFilter = sFirstFilter;
1920cdf0e10cSrcweir }
1921cdf0e10cSrcweir 
1922cdf0e10cSrcweir // ------------------------------------------------------------------------
addFilter(const OUString & rFilterName,const OUString & rExtension)1923cdf0e10cSrcweir void FileDialogHelper_Impl::addFilter( const OUString& rFilterName,
1924cdf0e10cSrcweir 									   const OUString& rExtension )
1925cdf0e10cSrcweir {
1926cdf0e10cSrcweir 	uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1927cdf0e10cSrcweir 
1928cdf0e10cSrcweir 	if ( ! xFltMgr.is() )
1929cdf0e10cSrcweir 		return;
1930cdf0e10cSrcweir 
1931cdf0e10cSrcweir 	try
1932cdf0e10cSrcweir 	{
1933cdf0e10cSrcweir 		xFltMgr->appendFilter( rFilterName, rExtension );
1934cdf0e10cSrcweir 
1935cdf0e10cSrcweir 		if ( !maSelectFilter.getLength() )
1936cdf0e10cSrcweir 			maSelectFilter = rFilterName;
1937cdf0e10cSrcweir 	}
1938cdf0e10cSrcweir 	catch( IllegalArgumentException )
1939cdf0e10cSrcweir 	{
1940cdf0e10cSrcweir #ifdef DBG_UTIL
1941cdf0e10cSrcweir 		ByteString aMsg( "Could not append Filter" );
1942cdf0e10cSrcweir 		aMsg += ByteString( String( rFilterName ), RTL_TEXTENCODING_UTF8 );
1943cdf0e10cSrcweir 		DBG_ERRORFILE( aMsg.GetBuffer() );
1944cdf0e10cSrcweir #endif
1945cdf0e10cSrcweir 	}
1946cdf0e10cSrcweir }
1947cdf0e10cSrcweir 
1948cdf0e10cSrcweir // ------------------------------------------------------------------------
addGraphicFilter()1949cdf0e10cSrcweir void FileDialogHelper_Impl::addGraphicFilter()
1950cdf0e10cSrcweir {
1951cdf0e10cSrcweir 	uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir 	if ( ! xFltMgr.is() )
1954cdf0e10cSrcweir 		return;
1955cdf0e10cSrcweir 
1956cdf0e10cSrcweir 	// create the list of filters
1957cdf0e10cSrcweir 	mpGraphicFilter = new GraphicFilter;
1958cdf0e10cSrcweir 	sal_uInt16 i, j, nCount = mpGraphicFilter->GetImportFormatCount();
1959cdf0e10cSrcweir 
1960cdf0e10cSrcweir 	// compute the extension string for all known import filters
1961cdf0e10cSrcweir 	String aExtensions;
1962cdf0e10cSrcweir 
1963cdf0e10cSrcweir 	for ( i = 0; i < nCount; i++ )
1964cdf0e10cSrcweir 	{
1965cdf0e10cSrcweir 		j = 0;
1966cdf0e10cSrcweir 		String sWildcard;
1967cdf0e10cSrcweir 		while( sal_True )
1968cdf0e10cSrcweir 		{
1969cdf0e10cSrcweir 			sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
1970cdf0e10cSrcweir 			if ( !sWildcard.Len() )
1971cdf0e10cSrcweir 				break;
1972cdf0e10cSrcweir 			if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
1973cdf0e10cSrcweir 			{
1974cdf0e10cSrcweir 				if ( aExtensions.Len() )
1975cdf0e10cSrcweir 					aExtensions += sal_Unicode(';');
1976cdf0e10cSrcweir 				aExtensions += sWildcard;
1977cdf0e10cSrcweir 			}
1978cdf0e10cSrcweir 		}
1979cdf0e10cSrcweir 	}
1980cdf0e10cSrcweir 
1981cdf0e10cSrcweir #if defined(WNT)
1982cdf0e10cSrcweir 	if ( aExtensions.Len() > 240 )
1983cdf0e10cSrcweir 		aExtensions = DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL );
1984cdf0e10cSrcweir #endif
1985cdf0e10cSrcweir 	sal_Bool bIsInOpenMode = isInOpenMode();
1986cdf0e10cSrcweir 
1987cdf0e10cSrcweir 	try
1988cdf0e10cSrcweir 	{
1989cdf0e10cSrcweir 		OUString aAllFilterName = String( SfxResId( STR_SFX_IMPORT_ALL ) );
1990cdf0e10cSrcweir 		aAllFilterName = ::sfx2::addExtension( aAllFilterName, aExtensions, bIsInOpenMode, *this );
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir 		xFltMgr->appendFilter( aAllFilterName, aExtensions );
1993cdf0e10cSrcweir 		maSelectFilter = aAllFilterName;
1994cdf0e10cSrcweir 	}
1995cdf0e10cSrcweir 	catch( IllegalArgumentException )
1996cdf0e10cSrcweir 	{
1997cdf0e10cSrcweir 		DBG_ERRORFILE( "Could not append Filter" );
1998cdf0e10cSrcweir 	}
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir 	// Now add the filter
2001cdf0e10cSrcweir 	for ( i = 0; i < nCount; i++ )
2002cdf0e10cSrcweir 	{
2003cdf0e10cSrcweir 		String aName = mpGraphicFilter->GetImportFormatName( i );
2004cdf0e10cSrcweir 		String aExt;
2005cdf0e10cSrcweir 		j = 0;
2006cdf0e10cSrcweir 		String sWildcard;
2007cdf0e10cSrcweir 		while( sal_True )
2008cdf0e10cSrcweir 		{
2009cdf0e10cSrcweir 			sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
2010cdf0e10cSrcweir 			if ( !sWildcard.Len() )
2011cdf0e10cSrcweir 				break;
2012cdf0e10cSrcweir 			if ( aExt.Search( sWildcard ) == STRING_NOTFOUND )
2013cdf0e10cSrcweir 			{
2014cdf0e10cSrcweir 				if ( aExt.Len() )
2015cdf0e10cSrcweir 					aExt += sal_Unicode(';');
2016cdf0e10cSrcweir 				aExt += sWildcard;
2017cdf0e10cSrcweir 			}
2018cdf0e10cSrcweir 		}
2019cdf0e10cSrcweir 		aName = ::sfx2::addExtension( aName, aExt, bIsInOpenMode, *this );
2020cdf0e10cSrcweir 		try
2021cdf0e10cSrcweir 		{
2022cdf0e10cSrcweir 			xFltMgr->appendFilter( aName, aExt );
2023cdf0e10cSrcweir 		}
2024cdf0e10cSrcweir 		catch( IllegalArgumentException )
2025cdf0e10cSrcweir 		{
2026cdf0e10cSrcweir 			DBG_ERRORFILE( "Could not append Filter" );
2027cdf0e10cSrcweir 		}
2028cdf0e10cSrcweir 	}
2029cdf0e10cSrcweir }
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir // ------------------------------------------------------------------------
2032cdf0e10cSrcweir #define GRF_CONFIG_STR		"   "
2033cdf0e10cSrcweir #define STD_CONFIG_STR		"1 "
2034cdf0e10cSrcweir 
saveConfig()2035cdf0e10cSrcweir void FileDialogHelper_Impl::saveConfig()
2036cdf0e10cSrcweir {
2037cdf0e10cSrcweir 	uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
2038cdf0e10cSrcweir 	Any aValue;
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir 	if ( ! xDlg.is() )
2041cdf0e10cSrcweir 		return;
2042cdf0e10cSrcweir 
2043cdf0e10cSrcweir 	if ( mbHasPreview )
2044cdf0e10cSrcweir 	{
2045cdf0e10cSrcweir 		SvtViewOptions aDlgOpt( E_DIALOG, IMPGRF_CONFIGNAME );
2046cdf0e10cSrcweir 		String aUserData = DEFINE_CONST_UNICODE( GRF_CONFIG_STR );
2047cdf0e10cSrcweir 
2048cdf0e10cSrcweir 		try
2049cdf0e10cSrcweir 		{
2050cdf0e10cSrcweir 			aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 );
2051cdf0e10cSrcweir 			sal_Bool bValue = sal_False;
2052cdf0e10cSrcweir 			aValue >>= bValue;
2053cdf0e10cSrcweir 			aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
2054cdf0e10cSrcweir 
2055cdf0e10cSrcweir 			aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
2056cdf0e10cSrcweir 			bValue = sal_False;
2057cdf0e10cSrcweir 			aValue >>= bValue;
2058cdf0e10cSrcweir 			aUserData.SetToken( 1, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
2059cdf0e10cSrcweir 
2060cdf0e10cSrcweir 			INetURLObject aObj( getPath() );
2061cdf0e10cSrcweir 
2062cdf0e10cSrcweir 			if ( aObj.GetProtocol() == INET_PROT_FILE )
2063cdf0e10cSrcweir 				aUserData.SetToken( 2, ' ', aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2064cdf0e10cSrcweir 
2065cdf0e10cSrcweir 			String aFilter = getFilter();
2066cdf0e10cSrcweir 			aFilter = EncodeSpaces_Impl( aFilter );
2067cdf0e10cSrcweir 			aUserData.SetToken( 3, ' ', aFilter );
2068cdf0e10cSrcweir 
2069cdf0e10cSrcweir 			aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
2070cdf0e10cSrcweir 		}
2071cdf0e10cSrcweir 		catch( IllegalArgumentException ){}
2072cdf0e10cSrcweir 	}
2073cdf0e10cSrcweir 	else
2074cdf0e10cSrcweir 	{
2075cdf0e10cSrcweir 		sal_Bool bWriteConfig = sal_False;
2076cdf0e10cSrcweir 		SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
2077cdf0e10cSrcweir 		String aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir 		if ( aDlgOpt.Exists() )
2080cdf0e10cSrcweir 		{
2081cdf0e10cSrcweir 			Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
2082cdf0e10cSrcweir 			OUString aTemp;
2083cdf0e10cSrcweir 			if ( aUserItem >>= aTemp )
2084cdf0e10cSrcweir 				aUserData = String( aTemp );
2085cdf0e10cSrcweir 		}
2086cdf0e10cSrcweir 
2087cdf0e10cSrcweir 		if ( mbHasAutoExt )
2088cdf0e10cSrcweir 		{
2089cdf0e10cSrcweir 			try
2090cdf0e10cSrcweir 			{
2091cdf0e10cSrcweir 				aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 );
2092cdf0e10cSrcweir 				sal_Bool bAutoExt = sal_True;
2093cdf0e10cSrcweir 				aValue >>= bAutoExt;
2094cdf0e10cSrcweir 				aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bAutoExt ) );
2095cdf0e10cSrcweir 				bWriteConfig = sal_True;
2096cdf0e10cSrcweir 			}
2097cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
2098cdf0e10cSrcweir 		}
2099cdf0e10cSrcweir 
2100cdf0e10cSrcweir 		if ( ! mbIsSaveDlg )
2101cdf0e10cSrcweir 		{
2102cdf0e10cSrcweir 			OUString aPath = getPath();
2103cdf0e10cSrcweir 			if ( aPath.getLength() &&
2104cdf0e10cSrcweir 				 utl::LocalFileHelper::IsLocalFile( aPath ) )
2105cdf0e10cSrcweir 			{
2106cdf0e10cSrcweir 				aUserData.SetToken( 1, ' ', aPath );
2107cdf0e10cSrcweir 				bWriteConfig = sal_True;
2108cdf0e10cSrcweir 			}
2109cdf0e10cSrcweir 		}
2110cdf0e10cSrcweir 
2111cdf0e10cSrcweir 		if( mbHasSelectionBox && mbSelectionFltrEnabled )
2112cdf0e10cSrcweir 		{
2113cdf0e10cSrcweir 			try
2114cdf0e10cSrcweir 			{
2115cdf0e10cSrcweir 				aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
2116cdf0e10cSrcweir 				sal_Bool bSelection = sal_True;
2117cdf0e10cSrcweir 				aValue >>= bSelection;
2118cdf0e10cSrcweir 				if ( aUserData.GetTokenCount(' ') < 3 )
2119cdf0e10cSrcweir 					aUserData.Append(' ');
2120cdf0e10cSrcweir 				aUserData.SetToken( 2, ' ', String::CreateFromInt32( (sal_Int32) bSelection ) );
2121cdf0e10cSrcweir 				bWriteConfig = sal_True;
2122cdf0e10cSrcweir 			}
2123cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
2124cdf0e10cSrcweir 		}
2125cdf0e10cSrcweir 
2126cdf0e10cSrcweir 		if ( bWriteConfig )
2127cdf0e10cSrcweir 			aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
2128cdf0e10cSrcweir 	}
2129cdf0e10cSrcweir 
2130cdf0e10cSrcweir 	SfxApplication *pSfxApp = SFX_APP();
2131cdf0e10cSrcweir 	pSfxApp->SetLastDir_Impl( getPath() );
2132cdf0e10cSrcweir }
2133cdf0e10cSrcweir 
2134cdf0e10cSrcweir // ------------------------------------------------------------------------
2135cdf0e10cSrcweir namespace
2136cdf0e10cSrcweir {
getInitPath(const String & _rFallback,const xub_StrLen _nFallbackToken)2137cdf0e10cSrcweir 	static ::rtl::OUString getInitPath( const String& _rFallback, const xub_StrLen _nFallbackToken )
2138cdf0e10cSrcweir 	{
2139cdf0e10cSrcweir 		SfxApplication *pSfxApp = SFX_APP();
2140cdf0e10cSrcweir 		String sPath = pSfxApp->GetLastDir_Impl();
2141cdf0e10cSrcweir 
2142cdf0e10cSrcweir 		if ( !sPath.Len() )
2143cdf0e10cSrcweir 			sPath = _rFallback.GetToken( _nFallbackToken, ' ' );
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir 		// check if the path points to a valid (accessible) directory
2146cdf0e10cSrcweir 		sal_Bool bValid = sal_False;
2147cdf0e10cSrcweir 		if ( sPath.Len() )
2148cdf0e10cSrcweir 		{
2149cdf0e10cSrcweir 			String sPathCheck( sPath );
2150cdf0e10cSrcweir 			if ( sPathCheck.GetBuffer()[ sPathCheck.Len() - 1 ] != '/' )
2151cdf0e10cSrcweir 				sPathCheck += '/';
2152cdf0e10cSrcweir 			sPathCheck += '.';
2153cdf0e10cSrcweir 			try
2154cdf0e10cSrcweir 			{
2155cdf0e10cSrcweir 				::ucbhelper::Content aContent( sPathCheck, uno::Reference< ucb::XCommandEnvironment >() );
2156cdf0e10cSrcweir 				bValid = aContent.isFolder();
2157cdf0e10cSrcweir 			}
2158cdf0e10cSrcweir 			catch( Exception& ) {}
2159cdf0e10cSrcweir 		}
2160cdf0e10cSrcweir 
2161cdf0e10cSrcweir 		if ( !bValid )
2162cdf0e10cSrcweir 			sPath.Erase();
2163cdf0e10cSrcweir 
2164cdf0e10cSrcweir 		return sPath;
2165cdf0e10cSrcweir 	}
2166cdf0e10cSrcweir }
2167cdf0e10cSrcweir 
2168cdf0e10cSrcweir // ------------------------------------------------------------------------
loadConfig()2169cdf0e10cSrcweir void FileDialogHelper_Impl::loadConfig()
2170cdf0e10cSrcweir {
2171cdf0e10cSrcweir 	uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
2172cdf0e10cSrcweir 	Any aValue;
2173cdf0e10cSrcweir 
2174cdf0e10cSrcweir 	if ( ! xDlg.is() )
2175cdf0e10cSrcweir 		return;
2176cdf0e10cSrcweir 
2177cdf0e10cSrcweir 	if ( mbHasPreview )
2178cdf0e10cSrcweir 	{
2179cdf0e10cSrcweir 		SvtViewOptions aViewOpt( E_DIALOG, IMPGRF_CONFIGNAME );
2180cdf0e10cSrcweir 		String aUserData;
2181cdf0e10cSrcweir 
2182cdf0e10cSrcweir 		if ( aViewOpt.Exists() )
2183cdf0e10cSrcweir 		{
2184cdf0e10cSrcweir 			Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2185cdf0e10cSrcweir 			OUString aTemp;
2186cdf0e10cSrcweir 			if ( aUserItem >>= aTemp )
2187cdf0e10cSrcweir 				aUserData = String( aTemp );
2188cdf0e10cSrcweir 		}
2189cdf0e10cSrcweir 
2190cdf0e10cSrcweir 		if ( aUserData.Len() > 0 )
2191cdf0e10cSrcweir 		{
2192cdf0e10cSrcweir 			try
2193cdf0e10cSrcweir 			{
2194cdf0e10cSrcweir 				// respect the last "insert as link" state
2195cdf0e10cSrcweir 				sal_Bool bLink = (sal_Bool) aUserData.GetToken( 0, ' ' ).ToInt32();
2196cdf0e10cSrcweir 				aValue <<= bLink;
2197cdf0e10cSrcweir 				xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aValue );
2198cdf0e10cSrcweir 
2199cdf0e10cSrcweir 				// respect the last "show preview" state
2200cdf0e10cSrcweir 				sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32();
2201cdf0e10cSrcweir 				aValue <<= bShowPreview;
2202cdf0e10cSrcweir 				xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
2203cdf0e10cSrcweir 
2204cdf0e10cSrcweir 				if ( !maPath.getLength() )
2205cdf0e10cSrcweir 					displayFolder( getInitPath( aUserData, 2 ) );
2206cdf0e10cSrcweir 
2207cdf0e10cSrcweir 				if ( ! maCurFilter.getLength() )
2208cdf0e10cSrcweir 				{
2209cdf0e10cSrcweir 					String aFilter = aUserData.GetToken( 3, ' ' );
2210cdf0e10cSrcweir 					aFilter = DecodeSpaces_Impl( aFilter );
2211cdf0e10cSrcweir 					setFilter( aFilter );
2212cdf0e10cSrcweir 				}
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir 				// set the member so we know that we have to show the preview
2215cdf0e10cSrcweir 				mbShowPreview = bShowPreview;
2216cdf0e10cSrcweir 			}
2217cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
2218cdf0e10cSrcweir 		}
2219cdf0e10cSrcweir 
2220cdf0e10cSrcweir 		if ( !maPath.getLength() )
2221cdf0e10cSrcweir 			displayFolder( SvtPathOptions().GetGraphicPath() );
2222cdf0e10cSrcweir 	}
2223cdf0e10cSrcweir 	else
2224cdf0e10cSrcweir 	{
2225cdf0e10cSrcweir 		SvtViewOptions aViewOpt( E_DIALOG, IODLG_CONFIGNAME );
2226cdf0e10cSrcweir 		String aUserData;
2227cdf0e10cSrcweir 
2228cdf0e10cSrcweir 		if ( aViewOpt.Exists() )
2229cdf0e10cSrcweir 		{
2230cdf0e10cSrcweir 			Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2231cdf0e10cSrcweir 			OUString aTemp;
2232cdf0e10cSrcweir 			if ( aUserItem >>= aTemp )
2233cdf0e10cSrcweir 				aUserData = String( aTemp );
2234cdf0e10cSrcweir 		}
2235cdf0e10cSrcweir 
2236cdf0e10cSrcweir 		if ( ! aUserData.Len() )
2237cdf0e10cSrcweir 			aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
2238cdf0e10cSrcweir 
2239cdf0e10cSrcweir 		if ( ! maPath.getLength() )
2240cdf0e10cSrcweir 			displayFolder( getInitPath( aUserData, 1 ) );
2241cdf0e10cSrcweir 
2242cdf0e10cSrcweir 		if ( mbHasAutoExt )
2243cdf0e10cSrcweir 		{
2244cdf0e10cSrcweir 			sal_Int32 nFlag = aUserData.GetToken( 0, ' ' ).ToInt32();
2245cdf0e10cSrcweir 			aValue <<= (sal_Bool) nFlag;
2246cdf0e10cSrcweir 			try
2247cdf0e10cSrcweir 			{
2248cdf0e10cSrcweir 				xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
2249cdf0e10cSrcweir 			}
2250cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
2251cdf0e10cSrcweir 		}
2252cdf0e10cSrcweir 
2253cdf0e10cSrcweir 		if( mbHasSelectionBox )
2254cdf0e10cSrcweir 		{
2255cdf0e10cSrcweir 			sal_Int32 nFlag = aUserData.GetToken( 2, ' ' ).ToInt32();
2256cdf0e10cSrcweir 			aValue <<= (sal_Bool) nFlag;
2257cdf0e10cSrcweir 			try
2258cdf0e10cSrcweir 			{
2259cdf0e10cSrcweir 				xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, aValue );
2260cdf0e10cSrcweir 			}
2261cdf0e10cSrcweir 			catch( IllegalArgumentException ){}
2262cdf0e10cSrcweir 		}
2263cdf0e10cSrcweir 
2264cdf0e10cSrcweir 		if ( !maPath.getLength() )
2265cdf0e10cSrcweir 			displayFolder( SvtPathOptions().GetWorkPath() );
2266cdf0e10cSrcweir 	}
2267cdf0e10cSrcweir }
2268cdf0e10cSrcweir 
2269cdf0e10cSrcweir // ------------------------------------------------------------------------
setDefaultValues()2270cdf0e10cSrcweir void FileDialogHelper_Impl::setDefaultValues()
2271cdf0e10cSrcweir {
2272cdf0e10cSrcweir 	// when no filter is set, we set the curentFilter to <all>
2273cdf0e10cSrcweir 	if ( !maCurFilter.getLength() && maSelectFilter.getLength() )
2274cdf0e10cSrcweir 	{
2275cdf0e10cSrcweir 		uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
2276cdf0e10cSrcweir 		try
2277cdf0e10cSrcweir 		{
2278cdf0e10cSrcweir 			xFltMgr->setCurrentFilter( maSelectFilter );
2279cdf0e10cSrcweir 		}
2280cdf0e10cSrcweir 		catch( IllegalArgumentException )
2281cdf0e10cSrcweir 		{}
2282cdf0e10cSrcweir 	}
2283cdf0e10cSrcweir 
2284cdf0e10cSrcweir 	// when no path is set, we use the standard 'work' folder
2285cdf0e10cSrcweir 	if ( ! maPath.getLength() )
2286cdf0e10cSrcweir 	{
2287cdf0e10cSrcweir 		OUString aWorkFolder = SvtPathOptions().GetWorkPath();
2288cdf0e10cSrcweir         try
2289cdf0e10cSrcweir         {
2290cdf0e10cSrcweir 		    mxFileDlg->setDisplayDirectory( aWorkFolder );
2291cdf0e10cSrcweir         }
2292cdf0e10cSrcweir         catch( const Exception& )
2293cdf0e10cSrcweir         {
2294cdf0e10cSrcweir             DBG_ERROR( "FileDialogHelper_Impl::setDefaultValues: caught an exception while setting the display directory!" );
2295cdf0e10cSrcweir         }
2296cdf0e10cSrcweir 
2297cdf0e10cSrcweir 		// INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
2298cdf0e10cSrcweir 		//SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
2299cdf0e10cSrcweir 	}
2300cdf0e10cSrcweir }
2301cdf0e10cSrcweir 
isShowFilterExtensionEnabled() const2302cdf0e10cSrcweir sal_Bool FileDialogHelper_Impl::isShowFilterExtensionEnabled() const
2303cdf0e10cSrcweir {
2304cdf0e10cSrcweir 	return !maFilters.empty();
2305cdf0e10cSrcweir }
2306cdf0e10cSrcweir 
addFilterPair(const OUString & rFilter,const OUString & rFilterWithExtension)2307cdf0e10cSrcweir void FileDialogHelper_Impl::addFilterPair( const OUString& rFilter,
2308cdf0e10cSrcweir 										   const OUString& rFilterWithExtension )
2309cdf0e10cSrcweir {
2310cdf0e10cSrcweir 	maFilters.push_back( FilterPair( rFilter, rFilterWithExtension ) );
2311cdf0e10cSrcweir 
2312cdf0e10cSrcweir }
2313cdf0e10cSrcweir 
getFilterName(const OUString & rFilterWithExtension) const2314cdf0e10cSrcweir OUString FileDialogHelper_Impl::getFilterName( const OUString& rFilterWithExtension ) const
2315cdf0e10cSrcweir {
2316cdf0e10cSrcweir 	OUString sRet;
2317cdf0e10cSrcweir 	for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
2318cdf0e10cSrcweir 	{
2319cdf0e10cSrcweir 		if ( (*pIter).Second == rFilterWithExtension )
2320cdf0e10cSrcweir 		{
2321cdf0e10cSrcweir 			sRet = (*pIter).First;
2322cdf0e10cSrcweir 			break;
2323cdf0e10cSrcweir 		}
2324cdf0e10cSrcweir 	}
2325cdf0e10cSrcweir 	return sRet;
2326cdf0e10cSrcweir }
2327cdf0e10cSrcweir 
getFilterWithExtension(const OUString & rFilter) const2328cdf0e10cSrcweir OUString FileDialogHelper_Impl::getFilterWithExtension( const OUString& rFilter ) const
2329cdf0e10cSrcweir {
2330cdf0e10cSrcweir 	OUString sRet;
2331cdf0e10cSrcweir 	for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
2332cdf0e10cSrcweir 	{
2333cdf0e10cSrcweir 		if ( (*pIter).First == rFilter )
2334cdf0e10cSrcweir 		{
2335cdf0e10cSrcweir 			sRet = (*pIter).Second;
2336cdf0e10cSrcweir 			break;
2337cdf0e10cSrcweir 		}
2338cdf0e10cSrcweir 	}
2339cdf0e10cSrcweir 	return sRet;
2340cdf0e10cSrcweir }
2341cdf0e10cSrcweir 
SetContext(FileDialogHelper::Context _eNewContext)2342cdf0e10cSrcweir void FileDialogHelper_Impl::SetContext( FileDialogHelper::Context _eNewContext )
2343cdf0e10cSrcweir {
2344cdf0e10cSrcweir 	meContext = _eNewContext;
2345cdf0e10cSrcweir 
2346cdf0e10cSrcweir 	sal_Int32		nNewHelpId = 0;
2347cdf0e10cSrcweir 	OUString		aConfigId;
2348cdf0e10cSrcweir 
2349cdf0e10cSrcweir 	switch( _eNewContext )
2350cdf0e10cSrcweir 	{
2351cdf0e10cSrcweir // #104952#	dependency to SVX not allowed! When used again, another solution has to be found
2352cdf0e10cSrcweir //		case FileDialogHelper::SW_INSERT_GRAPHIC:
2353cdf0e10cSrcweir //		case FileDialogHelper::SC_INSERT_GRAPHIC:
2354cdf0e10cSrcweir //		case FileDialogHelper::SD_INSERT_GRAPHIC:		nNewHelpId = SID_INSERT_GRAPHIC;		break;
2355cdf0e10cSrcweir 		case FileDialogHelper::SW_INSERT_SOUND:
2356cdf0e10cSrcweir 		case FileDialogHelper::SC_INSERT_SOUND:
2357cdf0e10cSrcweir 		case FileDialogHelper::SD_INSERT_SOUND:			nNewHelpId = SID_INSERT_SOUND;			break;
2358cdf0e10cSrcweir 		case FileDialogHelper::SW_INSERT_VIDEO:
2359cdf0e10cSrcweir 		case FileDialogHelper::SC_INSERT_VIDEO:
2360cdf0e10cSrcweir 		case FileDialogHelper::SD_INSERT_VIDEO:			nNewHelpId = SID_INSERT_VIDEO;			break;
2361cdf0e10cSrcweir               default: break;
2362cdf0e10cSrcweir 	}
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir 	const OUString*	pConfigId = GetLastFilterConfigId( _eNewContext );
2365cdf0e10cSrcweir 	if( pConfigId )
2366cdf0e10cSrcweir 		LoadLastUsedFilter( *pConfigId );
2367cdf0e10cSrcweir }
2368cdf0e10cSrcweir 
2369cdf0e10cSrcweir // ------------------------------------------------------------------------
2370cdf0e10cSrcweir // -----------			FileDialogHelper		---------------------------
2371cdf0e10cSrcweir // ------------------------------------------------------------------------
2372cdf0e10cSrcweir 
FileDialogHelper(sal_Int64 nFlags,const String & rFact,SfxFilterFlags nMust,SfxFilterFlags nDont)2373cdf0e10cSrcweir FileDialogHelper::FileDialogHelper(
2374cdf0e10cSrcweir     sal_Int64 nFlags,
2375cdf0e10cSrcweir     const String& rFact,
2376cdf0e10cSrcweir     SfxFilterFlags nMust,
2377cdf0e10cSrcweir     SfxFilterFlags nDont )
2378cdf0e10cSrcweir {
2379cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags );
2380cdf0e10cSrcweir 	mxImp = mpImp;
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir 	// create the list of filters
2383cdf0e10cSrcweir 	mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2384cdf0e10cSrcweir }
2385cdf0e10cSrcweir 
FileDialogHelper(sal_Int64 nFlags,const String & rFact,sal_Int16 nDialog,SfxFilterFlags nMust,SfxFilterFlags nDont,const String & rStandardDir,const::com::sun::star::uno::Sequence<::rtl::OUString> & rBlackList)2386cdf0e10cSrcweir FileDialogHelper::FileDialogHelper(
2387cdf0e10cSrcweir     sal_Int64 nFlags,
2388cdf0e10cSrcweir     const String& rFact,
2389cdf0e10cSrcweir 	sal_Int16 nDialog,
2390cdf0e10cSrcweir     SfxFilterFlags nMust,
2391cdf0e10cSrcweir     SfxFilterFlags nDont,
2392cdf0e10cSrcweir 	const String& rStandardDir,
2393cdf0e10cSrcweir 	const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
2394cdf0e10cSrcweir {
2395cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog, NULL , rStandardDir, rBlackList );
2396cdf0e10cSrcweir 	mxImp = mpImp;
2397cdf0e10cSrcweir 
2398cdf0e10cSrcweir 	// create the list of filters
2399cdf0e10cSrcweir 	mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2400cdf0e10cSrcweir }
2401cdf0e10cSrcweir 
FileDialogHelper(sal_Int64 nFlags,const String & rFact,sal_Int16 nDialog,SfxFilterFlags nMust,SfxFilterFlags nDont)2402cdf0e10cSrcweir FileDialogHelper::FileDialogHelper(
2403cdf0e10cSrcweir     sal_Int64 nFlags,
2404cdf0e10cSrcweir     const String& rFact,
2405cdf0e10cSrcweir 	sal_Int16 nDialog,
2406cdf0e10cSrcweir     SfxFilterFlags nMust,
2407cdf0e10cSrcweir     SfxFilterFlags nDont )
2408cdf0e10cSrcweir {
2409cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog );
2410cdf0e10cSrcweir 	mxImp = mpImp;
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir 	// create the list of filters
2413cdf0e10cSrcweir 	mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2414cdf0e10cSrcweir }
2415cdf0e10cSrcweir 
2416cdf0e10cSrcweir // ------------------------------------------------------------------------
FileDialogHelper(sal_Int64 nFlags)2417cdf0e10cSrcweir FileDialogHelper::FileDialogHelper( sal_Int64 nFlags )
2418cdf0e10cSrcweir {
2419cdf0e10cSrcweir 	sal_Int16 nDialogType = getDialogType( nFlags );
2420cdf0e10cSrcweir 
2421cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
2422cdf0e10cSrcweir 	mxImp = mpImp;
2423cdf0e10cSrcweir }
2424cdf0e10cSrcweir 
2425cdf0e10cSrcweir // ------------------------------------------------------------------------
FileDialogHelper(sal_Int16 nDialogType,sal_Int64 nFlags,const String & rFact,SfxFilterFlags nMust,SfxFilterFlags nDont)2426cdf0e10cSrcweir FileDialogHelper::FileDialogHelper(
2427cdf0e10cSrcweir     sal_Int16 nDialogType,
2428cdf0e10cSrcweir     sal_Int64 nFlags,
2429cdf0e10cSrcweir     const String& rFact,
2430cdf0e10cSrcweir     SfxFilterFlags nMust,
2431cdf0e10cSrcweir     SfxFilterFlags nDont )
2432cdf0e10cSrcweir {
2433cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
2434cdf0e10cSrcweir 	mxImp = mpImp;
2435cdf0e10cSrcweir 
2436cdf0e10cSrcweir 	// create the list of filters
2437cdf0e10cSrcweir 	mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2438cdf0e10cSrcweir }
2439cdf0e10cSrcweir 
2440cdf0e10cSrcweir // ------------------------------------------------------------------------
FileDialogHelper(sal_Int16 nDialogType,sal_Int64 nFlags,const String & rFact,sal_Int16 nDialog,SfxFilterFlags nMust,SfxFilterFlags nDont,const String & rStandardDir,const::com::sun::star::uno::Sequence<::rtl::OUString> & rBlackList)2441cdf0e10cSrcweir FileDialogHelper::FileDialogHelper(
2442cdf0e10cSrcweir     sal_Int16 nDialogType,
2443cdf0e10cSrcweir     sal_Int64 nFlags,
2444cdf0e10cSrcweir     const String& rFact,
2445cdf0e10cSrcweir 	sal_Int16 nDialog,
2446cdf0e10cSrcweir     SfxFilterFlags nMust,
2447cdf0e10cSrcweir     SfxFilterFlags nDont,
2448cdf0e10cSrcweir 	const String& rStandardDir,
2449cdf0e10cSrcweir 	const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
2450cdf0e10cSrcweir {
2451cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, nDialog, NULL, rStandardDir, rBlackList );
2452cdf0e10cSrcweir 	mxImp = mpImp;
2453cdf0e10cSrcweir 
2454cdf0e10cSrcweir 	// create the list of filters
2455cdf0e10cSrcweir 	mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2456cdf0e10cSrcweir }
2457cdf0e10cSrcweir 
2458cdf0e10cSrcweir // ------------------------------------------------------------------------
FileDialogHelper(sal_Int16 nDialogType,sal_Int64 nFlags,Window * _pPreferredParent)2459cdf0e10cSrcweir FileDialogHelper::FileDialogHelper(
2460cdf0e10cSrcweir     sal_Int16 nDialogType,
2461cdf0e10cSrcweir     sal_Int64 nFlags,
2462cdf0e10cSrcweir     Window* _pPreferredParent )
2463cdf0e10cSrcweir {
2464cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent );
2465cdf0e10cSrcweir 	mxImp = mpImp;
2466cdf0e10cSrcweir }
2467cdf0e10cSrcweir 
2468cdf0e10cSrcweir // ------------------------------------------------------------------------
FileDialogHelper(sal_Int16 nDialogType,sal_Int64 nFlags,const::rtl::OUString & aFilterUIName,const::rtl::OUString & aExtName,const::rtl::OUString & rStandardDir,const::com::sun::star::uno::Sequence<::rtl::OUString> & rBlackList,Window * _pPreferredParent)2469cdf0e10cSrcweir FileDialogHelper::FileDialogHelper(
2470cdf0e10cSrcweir     sal_Int16 nDialogType,
2471cdf0e10cSrcweir     sal_Int64 nFlags,
2472cdf0e10cSrcweir 	const ::rtl::OUString& aFilterUIName,
2473cdf0e10cSrcweir 	const ::rtl::OUString& aExtName,
2474cdf0e10cSrcweir 	const ::rtl::OUString& rStandardDir,
2475cdf0e10cSrcweir 	const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList,
2476cdf0e10cSrcweir     Window* _pPreferredParent )
2477cdf0e10cSrcweir {
2478cdf0e10cSrcweir 	mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent,rStandardDir, rBlackList );
2479cdf0e10cSrcweir 	mxImp = mpImp;
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir 	// the wildcard here is expected in form "*.extension"
2482cdf0e10cSrcweir 	::rtl::OUString aWildcard;
2483cdf0e10cSrcweir 	if ( aExtName.indexOf( (sal_Unicode)'*' ) != 0 )
2484cdf0e10cSrcweir 	{
2485cdf0e10cSrcweir 		if ( aExtName.getLength() && aExtName.indexOf( (sal_Unicode)'.' ) != 0 )
2486cdf0e10cSrcweir 			aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
2487cdf0e10cSrcweir 		else
2488cdf0e10cSrcweir 			aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*" ) );
2489cdf0e10cSrcweir 	}
2490cdf0e10cSrcweir 
2491cdf0e10cSrcweir 	aWildcard += aExtName;
2492cdf0e10cSrcweir 
2493cdf0e10cSrcweir 	::rtl::OUString aUIString =
2494cdf0e10cSrcweir 		::sfx2::addExtension( aFilterUIName, aWildcard, ( WB_OPEN == ( nFlags & WB_OPEN ) ), *mpImp );
2495cdf0e10cSrcweir 	AddFilter( aUIString, aWildcard );
2496cdf0e10cSrcweir }
2497cdf0e10cSrcweir 
2498cdf0e10cSrcweir // ------------------------------------------------------------------------
~FileDialogHelper()2499cdf0e10cSrcweir FileDialogHelper::~FileDialogHelper()
2500cdf0e10cSrcweir {
2501cdf0e10cSrcweir 	mpImp->dispose();
2502cdf0e10cSrcweir 	mxImp.clear();
2503cdf0e10cSrcweir }
2504cdf0e10cSrcweir 
2505cdf0e10cSrcweir // ------------------------------------------------------------------------
CreateMatcher(const String & rFactory)2506cdf0e10cSrcweir void FileDialogHelper::CreateMatcher( const String& rFactory )
2507cdf0e10cSrcweir {
2508cdf0e10cSrcweir 	mpImp->createMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
2509cdf0e10cSrcweir }
2510cdf0e10cSrcweir 
2511cdf0e10cSrcweir // ------------------------------------------------------------------------
SetControlHelpIds(const sal_Int16 * _pControlId,const char ** _pHelpId)2512cdf0e10cSrcweir void FileDialogHelper::SetControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
2513cdf0e10cSrcweir {
2514cdf0e10cSrcweir 	mpImp->setControlHelpIds( _pControlId, _pHelpId );
2515cdf0e10cSrcweir }
2516cdf0e10cSrcweir 
SetContext(Context _eNewContext)2517cdf0e10cSrcweir void FileDialogHelper::SetContext( Context _eNewContext )
2518cdf0e10cSrcweir {
2519cdf0e10cSrcweir 	mpImp->SetContext( _eNewContext );
2520cdf0e10cSrcweir }
2521cdf0e10cSrcweir 
2522cdf0e10cSrcweir // ------------------------------------------------------------------------
IMPL_LINK(FileDialogHelper,ExecuteSystemFilePicker,void *,EMPTYARG)2523cdf0e10cSrcweir IMPL_LINK( FileDialogHelper, ExecuteSystemFilePicker, void*, EMPTYARG )
2524cdf0e10cSrcweir {
2525cdf0e10cSrcweir     m_nError = mpImp->execute();
2526cdf0e10cSrcweir     if ( m_aDialogClosedLink.IsSet() )
2527cdf0e10cSrcweir         m_aDialogClosedLink.Call( this );
2528cdf0e10cSrcweir 
2529cdf0e10cSrcweir     return 0L;
2530cdf0e10cSrcweir }
2531cdf0e10cSrcweir 
2532cdf0e10cSrcweir // ------------------------------------------------------------------------
2533cdf0e10cSrcweir // rDirPath has to be a directory
Execute(SvStringsDtor * & rpURLList,SfxItemSet * & rpSet,String & rFilter,const String & rDirPath)2534cdf0e10cSrcweir ErrCode FileDialogHelper::Execute( SvStringsDtor*& rpURLList,
2535cdf0e10cSrcweir 								   SfxItemSet *&   rpSet,
2536cdf0e10cSrcweir 								   String&		   rFilter,
2537cdf0e10cSrcweir 								   const String&   rDirPath )
2538cdf0e10cSrcweir {
2539cdf0e10cSrcweir 	SetDisplayFolder( rDirPath );
2540cdf0e10cSrcweir 	return mpImp->execute( rpURLList, rpSet, rFilter );
2541cdf0e10cSrcweir }
2542cdf0e10cSrcweir 
2543cdf0e10cSrcweir 
2544cdf0e10cSrcweir // ------------------------------------------------------------------------
Execute()2545cdf0e10cSrcweir ErrCode FileDialogHelper::Execute()
2546cdf0e10cSrcweir {
2547cdf0e10cSrcweir 	return mpImp->execute();
2548cdf0e10cSrcweir }
2549cdf0e10cSrcweir 
2550cdf0e10cSrcweir // ------------------------------------------------------------------------
Execute(SfxItemSet * & rpSet,String & rFilter)2551cdf0e10cSrcweir ErrCode FileDialogHelper::Execute( SfxItemSet *&   rpSet,
2552cdf0e10cSrcweir 								   String&		   rFilter )
2553cdf0e10cSrcweir {
2554cdf0e10cSrcweir 	ErrCode nRet;
2555cdf0e10cSrcweir 	SvStringsDtor* pURLList;
2556cdf0e10cSrcweir 
2557cdf0e10cSrcweir 	nRet = mpImp->execute( pURLList, rpSet, rFilter );
2558cdf0e10cSrcweir 
2559cdf0e10cSrcweir 	delete pURLList;
2560cdf0e10cSrcweir 
2561cdf0e10cSrcweir 	return nRet;
2562cdf0e10cSrcweir }
2563cdf0e10cSrcweir 
StartExecuteModal(const Link & rEndDialogHdl)2564cdf0e10cSrcweir void FileDialogHelper::StartExecuteModal( const Link& rEndDialogHdl )
2565cdf0e10cSrcweir {
2566cdf0e10cSrcweir     m_aDialogClosedLink = rEndDialogHdl;
2567cdf0e10cSrcweir     m_nError = ERRCODE_NONE;
2568cdf0e10cSrcweir     if ( mpImp->isSystemFilePicker() )
2569cdf0e10cSrcweir         Application::PostUserEvent( LINK( this, FileDialogHelper, ExecuteSystemFilePicker ) );
2570cdf0e10cSrcweir     else
2571cdf0e10cSrcweir         mpImp->implStartExecute();
2572cdf0e10cSrcweir }
2573cdf0e10cSrcweir 
2574cdf0e10cSrcweir // ------------------------------------------------------------------------
2575cdf0e10cSrcweir 
GetDialogType() const2576cdf0e10cSrcweir short FileDialogHelper::GetDialogType() const
2577cdf0e10cSrcweir {
2578cdf0e10cSrcweir     return mpImp ? mpImp->m_nDialogType : 0;
2579cdf0e10cSrcweir }
2580cdf0e10cSrcweir 
2581cdf0e10cSrcweir // ------------------------------------------------------------------------
2582cdf0e10cSrcweir 
IsPasswordEnabled() const2583cdf0e10cSrcweir sal_Bool FileDialogHelper::IsPasswordEnabled() const
2584cdf0e10cSrcweir {
2585cdf0e10cSrcweir     return mpImp ? mpImp->isPasswordEnabled() : sal_False;
2586cdf0e10cSrcweir }
2587cdf0e10cSrcweir 
2588cdf0e10cSrcweir // ------------------------------------------------------------------------
2589cdf0e10cSrcweir 
GetRealFilter() const2590cdf0e10cSrcweir String FileDialogHelper::GetRealFilter() const
2591cdf0e10cSrcweir {
2592cdf0e10cSrcweir     String sFilter;
2593cdf0e10cSrcweir     if ( mpImp )
2594cdf0e10cSrcweir         mpImp->getRealFilter( sFilter );
2595cdf0e10cSrcweir     return sFilter;
2596cdf0e10cSrcweir }
2597cdf0e10cSrcweir 
2598cdf0e10cSrcweir // ------------------------------------------------------------------------
SetTitle(const String & rNewTitle)2599cdf0e10cSrcweir void FileDialogHelper::SetTitle( const String& rNewTitle )
2600cdf0e10cSrcweir {
2601cdf0e10cSrcweir     if ( mpImp->mxFileDlg.is() )
2602cdf0e10cSrcweir         mpImp->mxFileDlg->setTitle( rNewTitle );
2603cdf0e10cSrcweir }
2604cdf0e10cSrcweir 
2605cdf0e10cSrcweir // ------------------------------------------------------------------------
GetPath() const2606cdf0e10cSrcweir String FileDialogHelper::GetPath() const
2607cdf0e10cSrcweir {
2608cdf0e10cSrcweir 	OUString aPath;
2609cdf0e10cSrcweir 
2610cdf0e10cSrcweir     if ( mpImp->mlLastURLs.size() > 0)
2611cdf0e10cSrcweir         return mpImp->mlLastURLs[0];
2612cdf0e10cSrcweir 
2613cdf0e10cSrcweir 	if ( mpImp->mxFileDlg.is() )
2614cdf0e10cSrcweir 	{
2615cdf0e10cSrcweir 		Sequence < OUString > aPathSeq = mpImp->mxFileDlg->getFiles();
2616cdf0e10cSrcweir 
2617cdf0e10cSrcweir 		if ( aPathSeq.getLength() == 1 )
2618cdf0e10cSrcweir 		{
2619cdf0e10cSrcweir 			aPath = aPathSeq[0];
2620cdf0e10cSrcweir 		}
2621cdf0e10cSrcweir 	}
2622cdf0e10cSrcweir 
2623cdf0e10cSrcweir 	return aPath;
2624cdf0e10cSrcweir }
2625cdf0e10cSrcweir 
2626cdf0e10cSrcweir // ------------------------------------------------------------------------
GetMPath() const2627cdf0e10cSrcweir Sequence < OUString > FileDialogHelper::GetMPath() const
2628cdf0e10cSrcweir {
2629cdf0e10cSrcweir     if ( mpImp->mlLastURLs.size() > 0)
2630cdf0e10cSrcweir         return mpImp->mlLastURLs.getAsConstList();
2631cdf0e10cSrcweir 
2632cdf0e10cSrcweir 	if ( mpImp->mxFileDlg.is() )
2633cdf0e10cSrcweir 		return mpImp->mxFileDlg->getFiles();
2634cdf0e10cSrcweir 	else
2635cdf0e10cSrcweir 	{
2636cdf0e10cSrcweir 		Sequence < OUString > aEmpty;
2637cdf0e10cSrcweir 		return aEmpty;
2638cdf0e10cSrcweir 	}
2639cdf0e10cSrcweir }
2640cdf0e10cSrcweir 
2641cdf0e10cSrcweir // ------------------------------------------------------------------------
GetSelectedFiles() const2642cdf0e10cSrcweir Sequence< ::rtl::OUString > FileDialogHelper::GetSelectedFiles() const
2643cdf0e10cSrcweir {
2644cdf0e10cSrcweir     // a) the new way (optional!)
2645cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aResultSeq;
2646cdf0e10cSrcweir     uno::Reference< XFilePicker2 > xPickNew(mpImp->mxFileDlg, UNO_QUERY);
2647cdf0e10cSrcweir     if (xPickNew.is())
2648cdf0e10cSrcweir     {
2649cdf0e10cSrcweir         aResultSeq = xPickNew->getSelectedFiles();
2650cdf0e10cSrcweir     }
2651cdf0e10cSrcweir     // b) the olde way ... non optional.
2652cdf0e10cSrcweir     else
2653cdf0e10cSrcweir     {
2654cdf0e10cSrcweir         uno::Reference< XFilePicker > xPickOld(mpImp->mxFileDlg, UNO_QUERY_THROW);
2655cdf0e10cSrcweir         Sequence< OUString > lFiles = xPickOld->getFiles();
2656cdf0e10cSrcweir         ::sal_Int32          nFiles = lFiles.getLength();
2657cdf0e10cSrcweir         if ( nFiles > 1 )
2658cdf0e10cSrcweir         {
2659cdf0e10cSrcweir             aResultSeq = Sequence< ::rtl::OUString >( nFiles-1 );
2660cdf0e10cSrcweir 
2661cdf0e10cSrcweir             INetURLObject aPath( lFiles[0] );
2662cdf0e10cSrcweir             aPath.setFinalSlash();
2663cdf0e10cSrcweir 
2664cdf0e10cSrcweir             for (::sal_Int32 i = 1; i < nFiles; i++)
2665cdf0e10cSrcweir             {
2666cdf0e10cSrcweir                 if (i == 1)
2667cdf0e10cSrcweir                     aPath.Append( lFiles[i] );
2668cdf0e10cSrcweir                 else
2669cdf0e10cSrcweir                     aPath.setName( lFiles[i] );
2670cdf0e10cSrcweir 
2671cdf0e10cSrcweir                 aResultSeq[i-1] = ::rtl::OUString(aPath.GetMainURL( INetURLObject::NO_DECODE ));
2672cdf0e10cSrcweir             }
2673cdf0e10cSrcweir         }
2674cdf0e10cSrcweir         else
2675cdf0e10cSrcweir             aResultSeq = lFiles;
2676cdf0e10cSrcweir     }
2677cdf0e10cSrcweir 
2678cdf0e10cSrcweir     return aResultSeq;
2679cdf0e10cSrcweir }
2680cdf0e10cSrcweir 
2681cdf0e10cSrcweir // ------------------------------------------------------------------------
GetDisplayDirectory() const2682cdf0e10cSrcweir String FileDialogHelper::GetDisplayDirectory() const
2683cdf0e10cSrcweir {
2684cdf0e10cSrcweir 	return mpImp->getPath();
2685cdf0e10cSrcweir }
2686cdf0e10cSrcweir 
2687cdf0e10cSrcweir // ------------------------------------------------------------------------
GetCurrentFilter() const2688cdf0e10cSrcweir String FileDialogHelper::GetCurrentFilter() const
2689cdf0e10cSrcweir {
2690cdf0e10cSrcweir 	return mpImp->getFilter();
2691cdf0e10cSrcweir }
2692cdf0e10cSrcweir 
2693cdf0e10cSrcweir // ------------------------------------------------------------------------
GetGraphic(Graphic & rGraphic) const2694cdf0e10cSrcweir ErrCode FileDialogHelper::GetGraphic( Graphic& rGraphic ) const
2695cdf0e10cSrcweir {
2696cdf0e10cSrcweir 	return mpImp->getGraphic( rGraphic );
2697cdf0e10cSrcweir }
2698cdf0e10cSrcweir 
2699cdf0e10cSrcweir // ------------------------------------------------------------------------
impl_isFolder(const OUString & rPath)2700cdf0e10cSrcweir static int impl_isFolder( const OUString& rPath )
2701cdf0e10cSrcweir {
2702cdf0e10cSrcweir 	uno::Reference< task::XInteractionHandler > xHandler;
2703cdf0e10cSrcweir 	try
2704cdf0e10cSrcweir 	{
2705cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
2706cdf0e10cSrcweir         xHandler.set( xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.task.InteractionHandler" ) ),
2707cdf0e10cSrcweir                       uno::UNO_QUERY_THROW );
2708cdf0e10cSrcweir 	}
2709cdf0e10cSrcweir     catch ( Exception const & )
2710cdf0e10cSrcweir 	{
2711cdf0e10cSrcweir 	}
2712cdf0e10cSrcweir 
2713*3edf6992SAndrea Pescetti 	::rtl::Reference< ::comphelper::StillReadWriteInteraction > aHandler = new ::comphelper::StillReadWriteInteraction( xHandler , uno::Reference< task::XInteractionHandler >());
2714cdf0e10cSrcweir 
2715cdf0e10cSrcweir 	try
2716cdf0e10cSrcweir 	{
2717cdf0e10cSrcweir 		::ucbhelper::Content aContent(
2718cdf0e10cSrcweir 			rPath, new ::ucbhelper::CommandEnvironment( static_cast< task::XInteractionHandler* > ( aHandler.get() ), uno::Reference< ucb::XProgressHandler >() ) );
2719cdf0e10cSrcweir 		if ( aContent.isFolder() )
2720cdf0e10cSrcweir 			return 1;
2721cdf0e10cSrcweir 
2722cdf0e10cSrcweir 		return 0;
2723cdf0e10cSrcweir 	}
2724cdf0e10cSrcweir     catch ( Exception const & )
2725cdf0e10cSrcweir 	{
2726cdf0e10cSrcweir 	}
2727cdf0e10cSrcweir 
2728cdf0e10cSrcweir     return -1;
2729cdf0e10cSrcweir }
2730cdf0e10cSrcweir 
SetDisplayDirectory(const String & _rPath)2731cdf0e10cSrcweir void FileDialogHelper::SetDisplayDirectory( const String& _rPath )
2732cdf0e10cSrcweir {
2733cdf0e10cSrcweir     if ( !_rPath.Len() )
2734cdf0e10cSrcweir         return;
2735cdf0e10cSrcweir 
2736cdf0e10cSrcweir     // if the given path isn't a folder, we cut off the last part
2737cdf0e10cSrcweir     // and take it as filename and the rest of the path should be
2738cdf0e10cSrcweir     // the folder
2739cdf0e10cSrcweir 
2740cdf0e10cSrcweir     INetURLObject aObj( _rPath );
2741cdf0e10cSrcweir 
2742cdf0e10cSrcweir     ::rtl::OUString sFileName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
2743cdf0e10cSrcweir     aObj.removeSegment();
2744cdf0e10cSrcweir     ::rtl::OUString sPath = aObj.GetMainURL( INetURLObject::NO_DECODE );
2745cdf0e10cSrcweir 
2746cdf0e10cSrcweir     int nIsFolder = impl_isFolder( _rPath );
2747cdf0e10cSrcweir     if ( nIsFolder == 0 ||
2748cdf0e10cSrcweir          ( nIsFolder == -1 && impl_isFolder( sPath ) == 1 ) )
2749cdf0e10cSrcweir     {
2750cdf0e10cSrcweir         mpImp->setFileName( sFileName );
2751cdf0e10cSrcweir         mpImp->displayFolder( sPath );
2752cdf0e10cSrcweir     }
2753cdf0e10cSrcweir     else
2754cdf0e10cSrcweir     {
2755cdf0e10cSrcweir         INetURLObject aObjPathName( _rPath );
2756cdf0e10cSrcweir         ::rtl::OUString sFolder( aObjPathName.GetMainURL( INetURLObject::NO_DECODE ) );
2757cdf0e10cSrcweir         if ( sFolder.getLength() == 0 )
2758cdf0e10cSrcweir         {
2759cdf0e10cSrcweir             // _rPath is not a valid path -> fallback to home directory
2760cdf0e10cSrcweir             vos:: OSecurity  aSecurity;
2761cdf0e10cSrcweir             aSecurity.getHomeDir( sFolder );
2762cdf0e10cSrcweir         }
2763cdf0e10cSrcweir         mpImp->displayFolder( sFolder );
2764cdf0e10cSrcweir     }
2765cdf0e10cSrcweir }
2766cdf0e10cSrcweir 
2767cdf0e10cSrcweir // ------------------------------------------------------------------------
SetDisplayFolder(const String & _rURL)2768cdf0e10cSrcweir void FileDialogHelper::SetDisplayFolder( const String& _rURL )
2769cdf0e10cSrcweir {
2770cdf0e10cSrcweir     mpImp->displayFolder( _rURL );
2771cdf0e10cSrcweir }
2772cdf0e10cSrcweir 
2773cdf0e10cSrcweir // ------------------------------------------------------------------------
SetFileName(const String & _rFileName)2774cdf0e10cSrcweir void FileDialogHelper::SetFileName( const String& _rFileName )
2775cdf0e10cSrcweir {
2776cdf0e10cSrcweir     mpImp->setFileName( _rFileName );
2777cdf0e10cSrcweir }
2778cdf0e10cSrcweir 
2779cdf0e10cSrcweir // ------------------------------------------------------------------------
AddFilter(const String & rFilterName,const String & rExtension)2780cdf0e10cSrcweir void FileDialogHelper::AddFilter( const String& rFilterName,
2781cdf0e10cSrcweir 								  const String& rExtension )
2782cdf0e10cSrcweir {
2783cdf0e10cSrcweir 	mpImp->addFilter( rFilterName, rExtension );
2784cdf0e10cSrcweir }
2785cdf0e10cSrcweir 
2786cdf0e10cSrcweir // ------------------------------------------------------------------------
SetCurrentFilter(const String & rFilter)2787cdf0e10cSrcweir void FileDialogHelper::SetCurrentFilter( const String& rFilter )
2788cdf0e10cSrcweir {
2789cdf0e10cSrcweir 	String sFilter( rFilter );
2790cdf0e10cSrcweir 	if ( mpImp->isShowFilterExtensionEnabled() )
2791cdf0e10cSrcweir 		sFilter = mpImp->getFilterWithExtension( rFilter );
2792cdf0e10cSrcweir 	mpImp->setFilter( sFilter );
2793cdf0e10cSrcweir }
2794cdf0e10cSrcweir 
2795cdf0e10cSrcweir // ------------------------------------------------------------------------
GetFilePicker() const2796cdf0e10cSrcweir uno::Reference < XFilePicker > FileDialogHelper::GetFilePicker() const
2797cdf0e10cSrcweir {
2798cdf0e10cSrcweir 	return mpImp->mxFileDlg;
2799cdf0e10cSrcweir }
2800cdf0e10cSrcweir 
2801cdf0e10cSrcweir // ------------------------------------------------------------------------
getDialogType(sal_Int64 nFlags) const2802cdf0e10cSrcweir sal_Int16 FileDialogHelper::getDialogType( sal_Int64 nFlags ) const
2803cdf0e10cSrcweir {
2804cdf0e10cSrcweir 	sal_Int16 nDialogType = FILEOPEN_SIMPLE;
2805cdf0e10cSrcweir 
2806cdf0e10cSrcweir 	if ( nFlags & WB_SAVEAS )
2807cdf0e10cSrcweir 	{
2808cdf0e10cSrcweir 		if ( nFlags & SFXWB_PASSWORD )
2809cdf0e10cSrcweir 			nDialogType = FILESAVE_AUTOEXTENSION_PASSWORD;
2810cdf0e10cSrcweir 		else
2811cdf0e10cSrcweir 			nDialogType = FILESAVE_SIMPLE;
2812cdf0e10cSrcweir 	}
2813cdf0e10cSrcweir 	else if ( nFlags & SFXWB_GRAPHIC )
2814cdf0e10cSrcweir 	{
2815cdf0e10cSrcweir 		if ( nFlags & SFXWB_SHOWSTYLES )
2816cdf0e10cSrcweir 			nDialogType = FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
2817cdf0e10cSrcweir 		else
2818cdf0e10cSrcweir 			nDialogType = FILEOPEN_LINK_PREVIEW;
2819cdf0e10cSrcweir 	}
2820cdf0e10cSrcweir 	else if ( SFXWB_INSERT != ( nFlags & SFXWB_INSERT ) )
2821cdf0e10cSrcweir 		nDialogType = FILEOPEN_READONLY_VERSION;
2822cdf0e10cSrcweir 
2823cdf0e10cSrcweir 	return nDialogType;
2824cdf0e10cSrcweir }
2825cdf0e10cSrcweir 
2826cdf0e10cSrcweir // ------------------------------------------------------------------------
2827cdf0e10cSrcweir // XFilePickerListener Methods
2828cdf0e10cSrcweir // ------------------------------------------------------------------------
FileSelectionChanged(const FilePickerEvent & aEvent)2829cdf0e10cSrcweir void SAL_CALL FileDialogHelper::FileSelectionChanged( const FilePickerEvent& aEvent )
2830cdf0e10cSrcweir {
2831cdf0e10cSrcweir 	mpImp->handleFileSelectionChanged( aEvent );
2832cdf0e10cSrcweir }
2833cdf0e10cSrcweir 
2834cdf0e10cSrcweir // ------------------------------------------------------------------------
DirectoryChanged(const FilePickerEvent & aEvent)2835cdf0e10cSrcweir void SAL_CALL FileDialogHelper::DirectoryChanged( const FilePickerEvent& aEvent )
2836cdf0e10cSrcweir {
2837cdf0e10cSrcweir 	mpImp->handleDirectoryChanged( aEvent );
2838cdf0e10cSrcweir }
2839cdf0e10cSrcweir 
2840cdf0e10cSrcweir // ------------------------------------------------------------------------
HelpRequested(const FilePickerEvent & aEvent)2841cdf0e10cSrcweir OUString SAL_CALL FileDialogHelper::HelpRequested( const FilePickerEvent& aEvent )
2842cdf0e10cSrcweir {
2843cdf0e10cSrcweir 	return mpImp->handleHelpRequested( aEvent );
2844cdf0e10cSrcweir }
2845cdf0e10cSrcweir 
2846cdf0e10cSrcweir // ------------------------------------------------------------------------
ControlStateChanged(const FilePickerEvent & aEvent)2847cdf0e10cSrcweir void SAL_CALL FileDialogHelper::ControlStateChanged( const FilePickerEvent& aEvent )
2848cdf0e10cSrcweir {
2849cdf0e10cSrcweir 	mpImp->handleControlStateChanged( aEvent );
2850cdf0e10cSrcweir }
2851cdf0e10cSrcweir 
2852cdf0e10cSrcweir // ------------------------------------------------------------------------
DialogSizeChanged()2853cdf0e10cSrcweir void SAL_CALL FileDialogHelper::DialogSizeChanged()
2854cdf0e10cSrcweir {
2855cdf0e10cSrcweir     mpImp->handleDialogSizeChanged();
2856cdf0e10cSrcweir }
2857cdf0e10cSrcweir 
2858cdf0e10cSrcweir // ------------------------------------------------------------------------
DialogClosed(const DialogClosedEvent & _rEvent)2859cdf0e10cSrcweir void SAL_CALL FileDialogHelper::DialogClosed( const DialogClosedEvent& _rEvent )
2860cdf0e10cSrcweir {
2861cdf0e10cSrcweir     m_nError = ( RET_OK == _rEvent.DialogResult ) ? ERRCODE_NONE : ERRCODE_ABORT;
2862cdf0e10cSrcweir     if ( m_aDialogClosedLink.IsSet() )
2863cdf0e10cSrcweir         m_aDialogClosedLink.Call( this );
2864cdf0e10cSrcweir }
2865cdf0e10cSrcweir 
2866cdf0e10cSrcweir // ------------------------------------------------------------------------
2867cdf0e10cSrcweir // ------------------------------------------------------------------------
2868cdf0e10cSrcweir // ------------------------------------------------------------------------
2869cdf0e10cSrcweir 
FileOpenDialog_Impl(sal_Int64 nFlags,const String & rFact,SvStringsDtor * & rpURLList,String & rFilter,SfxItemSet * & rpSet,const String * pPath,sal_Int16 nDialog,const String & rStandardDir,const::com::sun::star::uno::Sequence<::rtl::OUString> & rBlackList)2870cdf0e10cSrcweir ErrCode FileOpenDialog_Impl( sal_Int64 nFlags,
2871cdf0e10cSrcweir                              const String& rFact,
2872cdf0e10cSrcweir                              SvStringsDtor *& rpURLList,
2873cdf0e10cSrcweir                              String& rFilter,
2874cdf0e10cSrcweir                              SfxItemSet *& rpSet,
2875cdf0e10cSrcweir                              const String* pPath,
2876cdf0e10cSrcweir 							 sal_Int16 nDialog,
2877cdf0e10cSrcweir 							 const String& rStandardDir,
2878cdf0e10cSrcweir 							 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
2879cdf0e10cSrcweir {
2880cdf0e10cSrcweir 	ErrCode nRet;
2881cdf0e10cSrcweir 	FileDialogHelper aDialog( nFlags, rFact, nDialog, 0, 0, rStandardDir, rBlackList );
2882cdf0e10cSrcweir 
2883cdf0e10cSrcweir     String aPath;
2884cdf0e10cSrcweir     if ( pPath )
2885cdf0e10cSrcweir         aPath = *pPath;
2886cdf0e10cSrcweir 
2887cdf0e10cSrcweir     nRet = aDialog.Execute( rpURLList, rpSet, rFilter, aPath );
2888cdf0e10cSrcweir 	DBG_ASSERT( rFilter.SearchAscii(": ") == STRING_NOTFOUND, "Old filter name used!");
2889cdf0e10cSrcweir 
2890cdf0e10cSrcweir 	return nRet;
2891cdf0e10cSrcweir }
2892cdf0e10cSrcweir 
2893cdf0e10cSrcweir 
2894cdf0e10cSrcweir // ------------------------------------------------------------------------
EncodeSpaces_Impl(const String & rSource)2895cdf0e10cSrcweir String EncodeSpaces_Impl( const String& rSource )
2896cdf0e10cSrcweir {
2897cdf0e10cSrcweir 	String sRet( rSource );
2898cdf0e10cSrcweir 	sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( " " ), DEFINE_CONST_UNICODE( "%20" ) );
2899cdf0e10cSrcweir 	return sRet;
2900cdf0e10cSrcweir }
2901cdf0e10cSrcweir 
2902cdf0e10cSrcweir // ------------------------------------------------------------------------
DecodeSpaces_Impl(const String & rSource)2903cdf0e10cSrcweir String DecodeSpaces_Impl( const String& rSource )
2904cdf0e10cSrcweir {
2905cdf0e10cSrcweir 	String sRet( rSource );
2906cdf0e10cSrcweir 	sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( "%20" ), DEFINE_CONST_UNICODE( " " ) );
2907cdf0e10cSrcweir 	return sRet;
2908cdf0e10cSrcweir }
2909cdf0e10cSrcweir 
2910cdf0e10cSrcweir // ------------------------------------------------------------------------
2911cdf0e10cSrcweir 
2912cdf0e10cSrcweir }	// end of namespace sfx2
2913cdf0e10cSrcweir 
2914