merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / dialog / filedlghelper.cxx
blob597af90ae0e27f298b0abeb40e54d3aca9423616
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filedlghelper.cxx,v $
10 * $Revision: 1.144 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <sfx2/filedlghelper.hxx>
34 #include <sal/types.h>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
37 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
39 #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
40 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
41 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
42 #include <com/sun/star/ui/dialogs/XControlInformation.hpp>
43 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
44 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
45 #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
46 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
47 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
48 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
49 #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
50 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/beans/NamedValue.hpp>
54 #include <com/sun/star/embed/ElementModes.hpp>
55 #include <com/sun/star/container/XEnumeration.hpp>
56 #include <com/sun/star/container/XContainerQuery.hpp>
57 #include <com/sun/star/task/XInteractionRequest.hpp>
58 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
60 #include <comphelper/processfactory.hxx>
61 #include <comphelper/types.hxx>
62 #include <comphelper/sequenceashashmap.hxx>
63 #include <tools/urlobj.hxx>
64 #include <vcl/help.hxx>
65 #include <unotools/ucbstreamhelper.hxx>
66 #include <unotools/ucbhelper.hxx>
67 #include <unotools/localfilehelper.hxx>
68 #include <vos/thread.hxx>
69 #include <vos/mutex.hxx>
70 #include <vos/security.hxx>
71 #include <vcl/cvtgrf.hxx>
72 #include <vcl/msgbox.hxx>
73 #include <vcl/mnemonic.hxx>
74 #include <svtools/pathoptions.hxx>
75 #include <svtools/securityoptions.hxx>
76 #include <svtools/itemset.hxx>
77 #include <svtools/eitem.hxx>
78 #include <svtools/intitem.hxx>
79 #include <svtools/stritem.hxx>
80 #include <svtools/filter.hxx>
81 #include <svtools/viewoptions.hxx>
82 #include <svtools/moduleoptions.hxx>
83 #include <svtools/helpid.hrc>
84 #include <svtools/pickerhelper.hxx>
85 #include <comphelper/docpasswordrequest.hxx>
86 #include <ucbhelper/content.hxx>
87 #include <ucbhelper/commandenvironment.hxx>
88 #include <comphelper/storagehelper.hxx>
89 #include <toolkit/helper/vclunohelper.hxx>
90 #include <sfx2/app.hxx>
91 #include <sfx2/docfile.hxx>
92 #include <sfx2/docfac.hxx>
93 #include "openflag.hxx"
94 #include <sfx2/passwd.hxx>
95 #include "sfxresid.hxx"
96 #include <sfx2/sfxsids.hrc>
97 #include "filedlghelper.hrc"
98 #include "filtergrouping.hxx"
99 #include <sfx2/request.hxx>
100 #include "filedlgimpl.hxx"
102 #include <sfxlocal.hrc>
104 //-----------------------------------------------------------------------------
106 using namespace ::com::sun::star;
107 using namespace ::com::sun::star::container;
108 using namespace ::com::sun::star::lang;
109 using namespace ::com::sun::star::ui::dialogs;
110 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
111 using namespace ::com::sun::star::uno;
112 using namespace ::com::sun::star::beans;
113 using namespace ::rtl;
114 using namespace ::cppu;
116 //-----------------------------------------------------------------------------
118 #define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save"))
119 #define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Graph"))
120 #define USERITEM_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UserItem" ))
122 //-----------------------------------------------------------------------------
124 namespace sfx2
127 const OUString* GetLastFilterConfigId( FileDialogHelper::Context _eContext )
129 static const OUString aSD_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SdExportLastFilter" ) );
130 static const OUString aSI_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SiExportLastFilter" ) );
131 static const OUString aSW_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SwExportLastFilter" ) );
133 const OUString* pRet = NULL;
135 switch( _eContext )
137 case FileDialogHelper::SD_EXPORT: pRet = &aSD_EXPORT_IDENTIFIER; break;
138 case FileDialogHelper::SI_EXPORT: pRet = &aSI_EXPORT_IDENTIFIER; break;
139 case FileDialogHelper::SW_EXPORT: pRet = &aSW_EXPORT_IDENTIFIER; break;
140 default: break;
143 return pRet;
146 String EncodeSpaces_Impl( const String& rSource );
147 String DecodeSpaces_Impl( const String& rSource );
149 // ------------------------------------------------------------------------
150 // ----------- FileDialogHelper_Impl ---------------------------
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
154 // XFilePickerListener Methods
155 // ------------------------------------------------------------------------
156 void SAL_CALL FileDialogHelper_Impl::fileSelectionChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
158 ::vos::OGuard aGuard( Application::GetSolarMutex() );
159 mpAntiImpl->FileSelectionChanged( aEvent );
162 // ------------------------------------------------------------------------
163 void SAL_CALL FileDialogHelper_Impl::directoryChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
165 ::vos::OGuard aGuard( Application::GetSolarMutex() );
166 mpAntiImpl->DirectoryChanged( aEvent );
169 // ------------------------------------------------------------------------
170 OUString SAL_CALL FileDialogHelper_Impl::helpRequested( const FilePickerEvent& aEvent ) throw ( RuntimeException )
172 ::vos::OGuard aGuard( Application::GetSolarMutex() );
173 return mpAntiImpl->HelpRequested( aEvent );
176 // ------------------------------------------------------------------------
177 void SAL_CALL FileDialogHelper_Impl::controlStateChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
179 ::vos::OGuard aGuard( Application::GetSolarMutex() );
180 mpAntiImpl->ControlStateChanged( aEvent );
183 // ------------------------------------------------------------------------
184 void SAL_CALL FileDialogHelper_Impl::dialogSizeChanged() throw ( RuntimeException )
186 ::vos::OGuard aGuard( Application::GetSolarMutex() );
187 mpAntiImpl->DialogSizeChanged();
190 // ------------------------------------------------------------------------
191 // XDialogClosedListener Methods
192 // ------------------------------------------------------------------------
193 void SAL_CALL FileDialogHelper_Impl::dialogClosed( const DialogClosedEvent& _rEvent ) throw ( RuntimeException )
195 ::vos::OGuard aGuard( Application::GetSolarMutex() );
196 mpAntiImpl->DialogClosed( _rEvent );
197 postExecute( _rEvent.DialogResult );
200 // ------------------------------------------------------------------------
201 // handle XFilePickerListener events
202 // ------------------------------------------------------------------------
203 void FileDialogHelper_Impl::handleFileSelectionChanged( const FilePickerEvent& )
205 if ( mbHasVersions )
206 updateVersions();
208 if ( mbShowPreview )
209 maPreViewTimer.Start();
212 // ------------------------------------------------------------------------
213 void FileDialogHelper_Impl::handleDirectoryChanged( const FilePickerEvent& )
215 if ( mbShowPreview )
216 TimeOutHdl_Impl( NULL );
219 // ------------------------------------------------------------------------
220 OUString FileDialogHelper_Impl::handleHelpRequested( const FilePickerEvent& aEvent )
222 //!!! todo: cache the help strings (here or TRA)
224 ULONG nHelpId = 0;
225 // mapping from element id -> help id
226 switch ( aEvent.ElementId )
228 case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION :
229 nHelpId = HID_FILESAVE_AUTOEXTENSION;
230 break;
232 case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
233 nHelpId = HID_FILESAVE_SAVEWITHPASSWORD;
234 break;
236 case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
237 nHelpId = HID_FILESAVE_CUSTOMIZEFILTER;
238 break;
240 case ExtendedFilePickerElementIds::CHECKBOX_READONLY :
241 nHelpId = HID_FILEOPEN_READONLY;
242 break;
244 case ExtendedFilePickerElementIds::CHECKBOX_LINK :
245 nHelpId = HID_FILEDLG_LINK_CB;
246 break;
248 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW :
249 nHelpId = HID_FILEDLG_PREVIEW_CB;
250 break;
252 case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY :
253 nHelpId = HID_FILESAVE_DOPLAY;
254 break;
256 case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL :
257 case ExtendedFilePickerElementIds::LISTBOX_VERSION :
258 nHelpId = HID_FILEOPEN_VERSION;
259 break;
261 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL :
262 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
263 nHelpId = HID_FILESAVE_TEMPLATE;
264 break;
266 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL :
267 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
268 nHelpId = HID_FILEOPEN_IMAGE_TEMPLATE;
269 break;
271 case ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
272 nHelpId = HID_FILESAVE_SELECTION;
273 break;
275 default:
276 DBG_ERRORFILE( "invalid element id" );
279 OUString aHelpText;
280 Help* pHelp = Application::GetHelp();
281 if ( pHelp )
282 aHelpText = String( pHelp->GetHelpText( nHelpId, NULL ) );
283 return aHelpText;
286 // ------------------------------------------------------------------------
287 void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aEvent )
289 switch ( aEvent.ElementId )
291 case CommonFilePickerElementIds::LISTBOX_FILTER:
292 updateFilterOptionsBox();
293 enablePasswordBox( sal_False );
294 updateSelectionBox();
295 // only use it for export and with our own dialog
296 if ( mbExport && !mbSystemPicker )
297 updateExportButton();
298 break;
300 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
301 updatePreviewState();
302 break;
306 // ------------------------------------------------------------------------
307 void FileDialogHelper_Impl::handleDialogSizeChanged()
309 if ( mbShowPreview )
310 TimeOutHdl_Impl( NULL );
313 // ------------------------------------------------------------------------
314 // XEventListener Methods
315 // ------------------------------------------------------------------------
316 void SAL_CALL FileDialogHelper_Impl::disposing( const EventObject& ) throw ( RuntimeException )
318 ::vos::OGuard aGuard( Application::GetSolarMutex() );
319 dispose();
322 // ------------------------------------------------------------------------
323 // ------------------------------------------------------------------------
324 // ------------------------------------------------------------------------
325 void FileDialogHelper_Impl::dispose()
327 if ( mxFileDlg.is() )
329 // remove the event listener
330 uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
331 if ( xNotifier.is() )
332 xNotifier->removeFilePickerListener( this );
334 ::comphelper::disposeComponent( mxFileDlg );
335 mxFileDlg.clear();
339 // ------------------------------------------------------------------------
340 String FileDialogHelper_Impl::getCurrentFilterUIName() const
342 String aFilterName;
343 uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
345 if( xFltMgr.is() )
347 aFilterName = xFltMgr->getCurrentFilter();
349 if ( aFilterName.Len() && isShowFilterExtensionEnabled() )
350 aFilterName = getFilterName( aFilterName );
353 return aFilterName;
356 // ------------------------------------------------------------------------
357 void FileDialogHelper_Impl::LoadLastUsedFilter( const OUString& _rContextIdentifier )
359 SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
361 if( aDlgOpt.Exists() )
363 OUString aLastFilter;
364 if( aDlgOpt.GetUserItem( _rContextIdentifier ) >>= aLastFilter )
365 setFilter( aLastFilter );
369 // ------------------------------------------------------------------------
370 void FileDialogHelper_Impl::SaveLastUsedFilter( const OUString& _rContextIdentifier )
372 SvtViewOptions( E_DIALOG, IODLG_CONFIGNAME ).SetUserItem( _rContextIdentifier,
373 makeAny( getFilterWithExtension( getFilter() ) ) );
376 // ------------------------------------------------------------------------
377 void FileDialogHelper_Impl::SaveLastUsedFilter( void )
379 const OUString* pConfigId = GetLastFilterConfigId( meContext );
380 if( pConfigId )
381 SaveLastUsedFilter( *pConfigId );
384 // ------------------------------------------------------------------------
385 const SfxFilter* FileDialogHelper_Impl::getCurentSfxFilter()
387 String aFilterName = getCurrentFilterUIName();
389 const SfxFilter* pFilter = NULL;
390 if ( mpMatcher && aFilterName.Len() )
391 pFilter = mpMatcher->GetFilter4UIName( aFilterName, m_nMustFlags, m_nDontFlags );
393 return pFilter;
396 // ------------------------------------------------------------------------
397 sal_Bool FileDialogHelper_Impl::updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable )
399 sal_Bool bIsEnabled = sal_False;
401 uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
402 if ( xCtrlAccess.is() )
406 xCtrlAccess->enableControl( _nExtendedControlId, _bEnable );
407 bIsEnabled = _bEnable;
409 catch( const IllegalArgumentException& )
411 DBG_ERROR( "FileDialogHelper_Impl::updateExtendedControl: caught an exception!" );
414 return bIsEnabled;
417 // ------------------------------------------------------------------------
418 sal_Bool FileDialogHelper_Impl::CheckFilterOptionsCapability( const SfxFilter* _pFilter )
420 sal_Bool bResult = sal_False;
422 if( mxFilterCFG.is() && _pFilter )
424 try {
425 Sequence < PropertyValue > aProps;
426 Any aAny = mxFilterCFG->getByName( _pFilter->GetName() );
427 if ( aAny >>= aProps )
429 ::rtl::OUString aServiceName;
430 sal_Int32 nPropertyCount = aProps.getLength();
431 for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
433 if( aProps[nProperty].Name.equals( DEFINE_CONST_OUSTRING( "UIComponent") ) )
435 aProps[nProperty].Value >>= aServiceName;
436 if( aServiceName.getLength() )
437 bResult = sal_True;
442 catch( Exception& )
447 return bResult;
450 // ------------------------------------------------------------------------
451 sal_Bool FileDialogHelper_Impl::isInOpenMode() const
453 sal_Bool bRet = sal_False;
455 switch ( m_nDialogType )
457 case FILEOPEN_SIMPLE:
458 case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
459 case FILEOPEN_PLAY:
460 case FILEOPEN_READONLY_VERSION:
461 case FILEOPEN_LINK_PREVIEW:
462 bRet = sal_True;
465 return bRet;
468 // ------------------------------------------------------------------------
470 namespace {
472 bool lclCheckODFPasswordCapability( const SfxFilter* pFilter )
474 return pFilter && pFilter->IsOwnFormat() && pFilter->UsesStorage() && (pFilter->GetVersion() >= SOFFICE_FILEFORMAT_60);
477 bool lclCheckMSPasswordCapability( const SfxFilter* pFilter )
479 // TODO #i105076# this should be in the filter configuration!!!
480 return pFilter && CheckMSPasswordCapabilityForExport( pFilter->GetFilterName() );
483 bool lclCheckPasswordCapability( const SfxFilter* pFilter )
485 return
486 lclCheckODFPasswordCapability( pFilter ) ||
487 // TODO #i105076# this should be in the filter configuration!!!
488 lclCheckMSPasswordCapability( pFilter );
493 // ------------------------------------------------------------------------
495 void FileDialogHelper_Impl::updateFilterOptionsBox()
497 if ( !m_bHaveFilterOptions )
498 return;
500 updateExtendedControl(
501 ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS,
502 CheckFilterOptionsCapability( getCurentSfxFilter() )
506 // ------------------------------------------------------------------------
508 void FileDialogHelper_Impl::updateExportButton()
510 uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
511 if ( xCtrlAccess.is() )
513 OUString sEllipses( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
514 OUString sOldLabel( xCtrlAccess->getLabel( CommonFilePickerElementIds::PUSHBUTTON_OK ) );
516 // initialize button label; we need the label with the mnemonic char
517 if ( !maButtonLabel.getLength() || maButtonLabel.indexOf( MNEMONIC_CHAR ) == -1 )
519 // cut the ellipses, if necessary
520 sal_Int32 nIndex = sOldLabel.indexOf( sEllipses );
521 if ( -1 == nIndex )
522 nIndex = sOldLabel.getLength();
523 maButtonLabel = sOldLabel.copy( 0, nIndex );
526 OUString sLabel = maButtonLabel;
527 // filter with options -> append ellipses on export button label
528 if ( CheckFilterOptionsCapability( getCurentSfxFilter() ) )
529 sLabel += OUString( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
531 if ( sOldLabel != sLabel )
535 xCtrlAccess->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, sLabel );
537 catch( const IllegalArgumentException& )
539 DBG_ERRORFILE( "FileDialogHelper_Impl::updateExportButton: caught an exception!" );
545 // ------------------------------------------------------------------------
546 void FileDialogHelper_Impl::updateSelectionBox()
548 if ( !mbExport )
549 return;
551 // Does the selection box exist?
552 bool bSelectionBoxFound = false;
553 uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY );
554 if ( xCtrlInfo.is() )
556 Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls();
557 sal_uInt32 nCount = aCtrlList.getLength();
558 for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl )
559 if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") )
561 bSelectionBoxFound = true;
562 break;
566 if ( bSelectionBoxFound )
568 const SfxFilter* pFilter = getCurentSfxFilter();
569 updateExtendedControl(
570 ExtendedFilePickerElementIds::CHECKBOX_SELECTION,
571 ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) );
572 uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
573 xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) );
577 // ------------------------------------------------------------------------
578 void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit )
580 if ( ! mbHasPassword )
581 return;
583 sal_Bool bWasEnabled = mbIsPwdEnabled;
585 mbIsPwdEnabled = updateExtendedControl(
586 ExtendedFilePickerElementIds::CHECKBOX_PASSWORD,
587 lclCheckPasswordCapability( getCurentSfxFilter() )
590 if( bInit )
592 // in case of inintialization previous state is not interesting
593 if( mbIsPwdEnabled )
595 uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
596 if( mbPwdCheckBoxState )
597 xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
600 else if( !bWasEnabled && mbIsPwdEnabled )
602 uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
603 if( mbPwdCheckBoxState )
604 xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
606 else if( bWasEnabled && !mbIsPwdEnabled )
608 // remember user settings until checkbox is enabled
609 uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
610 Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
611 sal_Bool bPassWord = sal_False;
612 mbPwdCheckBoxState = ( aValue >>= bPassWord ) && bPassWord;
613 xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_False ) );
617 // ------------------------------------------------------------------------
618 void FileDialogHelper_Impl::updatePreviewState( sal_Bool _bUpdatePreviewWindow )
620 if ( mbHasPreview )
622 uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
624 // check, wether or not we have to display a preview
625 if ( xCtrlAccess.is() )
629 Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
630 sal_Bool bShowPreview = sal_False;
632 if ( aValue >>= bShowPreview )
634 mbShowPreview = bShowPreview;
636 // #97633
637 // setShowState has currently no effect for the
638 // OpenOffice FilePicker (see svtools/source/filepicker/iodlg.cxx)
639 uno::Reference< XFilePreview > xFilePreview( mxFileDlg, UNO_QUERY );
640 if ( xFilePreview.is() )
641 xFilePreview->setShowState( mbShowPreview );
643 if ( _bUpdatePreviewWindow )
644 TimeOutHdl_Impl( NULL );
647 catch( Exception )
649 DBG_ERRORFILE( "FileDialogHelper_Impl::updatePreviewState: caught an exception!" );
655 // ------------------------------------------------------------------------
656 void FileDialogHelper_Impl::updateVersions()
658 Sequence < OUString > aEntries;
659 Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
661 if ( aPathSeq.getLength() == 1 )
663 INetURLObject aObj( aPathSeq[0] );
665 if ( ( aObj.GetProtocol() == INET_PROT_FILE ) &&
666 ( utl::UCBContentHelper::IsDocument( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) )
670 uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
671 aObj.GetMainURL( INetURLObject::NO_DECODE ),
672 embed::ElementModes::READ );
674 DBG_ASSERT( xStorage.is(), "The method must return the storage or throw an exception!" );
675 if ( !xStorage.is() )
676 throw uno::RuntimeException();
678 uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
680 aEntries.realloc( xVersions.getLength() + 1 );
681 aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
683 for ( sal_Int32 i=0; i<xVersions.getLength(); i++ )
684 aEntries[ i + 1 ] = xVersions[i].Identifier;
686 // TODO/LATER: not sure that this information must be shown in future ( binfilter? )
687 //REMOVE else
688 //REMOVE {
689 //REMOVE SfxFilterFlags nMust = SFX_FILTER_IMPORT | SFX_FILTER_OWN;
690 //REMOVE SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED | SFX_FILTER_STARONEFILTER;
691 //REMOVE if ( SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( pStor->GetFormat(), nMust, nDont ) )
692 //REMOVE {
693 //REMOVE aEntries.realloc( 1 );
694 //REMOVE aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
695 //REMOVE }
696 //REMOVE }
698 catch( uno::Exception& )
704 uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
705 Any aValue;
709 xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
710 ControlActions::DELETE_ITEMS, aValue );
712 catch( IllegalArgumentException ){}
714 sal_Int32 nCount = aEntries.getLength();
716 if ( nCount )
720 aValue <<= aEntries;
721 xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
722 ControlActions::ADD_ITEMS, aValue );
724 Any aPos;
725 aPos <<= (sal_Int32) 0;
726 xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
727 ControlActions::SET_SELECT_ITEM, aPos );
729 catch( IllegalArgumentException ){}
733 // -----------------------------------------------------------------------
734 class OReleaseSolarMutex
736 private:
737 const sal_Int32 m_nAquireCount;
738 public:
739 OReleaseSolarMutex( )
740 :m_nAquireCount( Application::ReleaseSolarMutex() )
743 ~OReleaseSolarMutex( )
745 Application::AcquireSolarMutex( m_nAquireCount );
749 // -----------------------------------------------------------------------
750 IMPL_LINK( FileDialogHelper_Impl, TimeOutHdl_Impl, Timer*, EMPTYARG )
752 if ( !mbHasPreview )
753 return 0;
755 maGraphic.Clear();
757 Any aAny;
758 uno::Reference < XFilePreview > xFilePicker( mxFileDlg, UNO_QUERY );
760 if ( ! xFilePicker.is() )
761 return 0;
763 Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
765 if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) )
767 OUString aURL = aPathSeq[0];
769 if ( ERRCODE_NONE == getGraphic( aURL, maGraphic ) )
771 // #89491
772 // changed the code slightly;
773 // before: the bitmap was scaled and
774 // surrounded a white frame
775 // now: the bitmap will only be scaled
776 // and the filepicker implementation
777 // is responsible for placing it at its
778 // proper position and painting a frame
780 Bitmap aBmp = maGraphic.GetBitmap();
782 // scale the bitmap to the correct size
783 sal_Int32 nOutWidth = xFilePicker->getAvailableWidth();
784 sal_Int32 nOutHeight = xFilePicker->getAvailableHeight();
785 sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
786 sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
788 double nXRatio = (double) nOutWidth / nBmpWidth;
789 double nYRatio = (double) nOutHeight / nBmpHeight;
791 if ( nXRatio < nYRatio )
792 aBmp.Scale( nXRatio, nXRatio );
793 else
794 aBmp.Scale( nYRatio, nYRatio );
796 // #94505# Convert to true color, to allow CopyPixel
797 aBmp.Convert( BMP_CONVERSION_24BIT );
799 // and copy it into the Any
800 SvMemoryStream aData;
802 aData << aBmp;
804 Sequence < sal_Int8 > aBuffer( (sal_Int8*) aData.GetData(), aData.GetSize() );
806 aAny <<= aBuffer;
812 OReleaseSolarMutex aReleaseForCallback;
813 // clear the preview window
814 xFilePicker->setImage( FilePreviewImageFormats::BITMAP, aAny );
816 catch( IllegalArgumentException )
820 return 0;
823 // ------------------------------------------------------------------------
824 ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL,
825 Graphic& rGraphic ) const
827 if ( utl::UCBContentHelper::IsFolder( rURL ) )
828 return ERRCODE_IO_NOTAFILE;
830 if ( !mpGraphicFilter )
831 return ERRCODE_IO_NOTSUPPORTED;
833 // select graphic filter from dialog filter selection
834 OUString aCurFilter( getFilter() );
836 sal_uInt16 nFilter = aCurFilter.getLength() && mpGraphicFilter->GetImportFormatCount()
837 ? mpGraphicFilter->GetImportFormatNumber( aCurFilter )
838 : GRFILTER_FORMAT_DONTKNOW;
840 INetURLObject aURLObj( rURL );
842 if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
844 aURLObj.SetSmartProtocol( INET_PROT_FILE );
845 aURLObj.SetSmartURL( rURL );
848 ErrCode nRet = ERRCODE_NONE;
850 sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
851 // non-local?
852 if ( INET_PROT_FILE != aURLObj.GetProtocol() )
854 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
856 if( pStream )
857 nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, NULL, nFilterImportFlags );
858 else
859 nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
860 delete pStream;
862 else
864 nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
867 return nRet;
870 // ------------------------------------------------------------------------
871 ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const
873 ErrCode nRet = ERRCODE_NONE;
875 if ( ! maGraphic )
877 OUString aPath;;
878 Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
880 if ( aPathSeq.getLength() == 1 )
882 aPath = aPathSeq[0];
885 if ( aPath.getLength() )
886 nRet = getGraphic( aPath, rGraphic );
887 else
888 nRet = ERRCODE_IO_GENERAL;
890 else
891 rGraphic = maGraphic;
893 return nRet;
896 // ------------------------------------------------------------------------
897 sal_Bool lcl_isSystemFilePicker( const uno::Reference< XFilePicker >& _rxFP )
901 uno::Reference< XServiceInfo > xSI( _rxFP, UNO_QUERY );
902 if ( xSI.is() && xSI->supportsService( DEFINE_CONST_OUSTRING( "com.sun.star.ui.dialogs.SystemFilePicker" ) ) )
903 return sal_True;
905 catch( const Exception& )
908 return sal_False;
912 // ------------------------------------------------------------------------
913 // ----------- FileDialogHelper_Impl ---------------------------
914 // ------------------------------------------------------------------------
916 FileDialogHelper_Impl::FileDialogHelper_Impl(
917 FileDialogHelper* _pAntiImpl,
918 sal_Int16 nDialogType,
919 sal_Int64 nFlags,
920 sal_Int16 nDialog,
921 Window* _pPreferredParentWindow,
922 const String& sStandardDir,
923 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
925 :m_nDialogType ( nDialogType )
926 ,meContext ( FileDialogHelper::UNKNOWN_CONTEXT )
928 const char* pServiceName=0;
929 if ( nDialog == SFX2_IMPL_DIALOG_SYSTEM )
930 pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
931 else if ( nDialog == SFX2_IMPL_DIALOG_OOO )
932 pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
933 else
934 pServiceName = FILE_OPEN_SERVICE_NAME;
935 OUString aService = ::rtl::OUString::createFromAscii( pServiceName );
937 uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
939 // create the file open dialog
940 // the flags can be SFXWB_INSERT or SFXWB_MULTISELECTION
942 mpPreferredParentWindow = _pPreferredParentWindow;
943 mpAntiImpl = _pAntiImpl;
944 mnError = ERRCODE_NONE;
945 mbHasAutoExt = sal_False;
946 mbHasPassword = sal_False;
947 m_bHaveFilterOptions = sal_False;
948 mbIsPwdEnabled = sal_True;
949 mbHasVersions = sal_False;
950 mbHasPreview = sal_False;
951 mbShowPreview = sal_False;
952 mbHasLink = sal_False;
953 mbDeleteMatcher = sal_False;
954 mbInsert = SFXWB_INSERT == ( nFlags & SFXWB_INSERT );
955 mbExport = SFXWB_EXPORT == ( nFlags & SFXWB_EXPORT );
956 mbIsSaveDlg = sal_False;
957 mbPwdCheckBoxState = sal_False;
958 mbSelection = sal_False;
959 mbSelectionEnabled = sal_True;
961 // default settings
962 m_nDontFlags = SFX_FILTER_INTERNAL | SFX_FILTER_NOTINFILEDLG | SFX_FILTER_NOTINSTALLED;
963 if( WB_OPEN == ( nFlags & WB_OPEN ) )
964 m_nMustFlags = SFX_FILTER_IMPORT;
965 else
966 m_nMustFlags = SFX_FILTER_EXPORT;
969 mpMatcher = NULL;
970 mpGraphicFilter = NULL;
971 mnPostUserEventId = 0;
973 // create the picker component
974 mxFileDlg = mxFileDlg.query( xFactory->createInstance( aService ) );
975 mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg );
977 uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
978 uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY );
980 if ( ! mxFileDlg.is() || ! xNotifier.is() )
982 mnError = ERRCODE_ABORT;
983 return;
987 if ( xInit.is() )
989 sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
991 switch ( m_nDialogType )
993 case FILEOPEN_SIMPLE:
994 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
995 break;
997 case FILESAVE_SIMPLE:
998 nTemplateDescription = TemplateDescription::FILESAVE_SIMPLE;
999 mbIsSaveDlg = sal_True;
1000 break;
1002 case FILESAVE_AUTOEXTENSION_PASSWORD:
1003 nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
1004 mbHasPassword = sal_True;
1005 mbHasAutoExt = sal_True;
1006 mbIsSaveDlg = sal_True;
1007 break;
1009 case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
1010 nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS;
1011 mbHasPassword = sal_True;
1013 m_bHaveFilterOptions = sal_True;
1014 if( xFactory.is() )
1016 mxFilterCFG = uno::Reference< XNameAccess >(
1017 xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
1018 UNO_QUERY );
1021 mbHasAutoExt = sal_True;
1022 mbIsSaveDlg = sal_True;
1023 break;
1025 case FILESAVE_AUTOEXTENSION_SELECTION:
1026 nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION;
1027 mbHasAutoExt = sal_True;
1028 mbIsSaveDlg = sal_True;
1029 if ( mbExport && !mxFilterCFG.is() && xFactory.is() )
1031 mxFilterCFG = uno::Reference< XNameAccess >(
1032 xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
1033 UNO_QUERY );
1035 break;
1037 case FILESAVE_AUTOEXTENSION_TEMPLATE:
1038 nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE;
1039 mbHasAutoExt = sal_True;
1040 mbIsSaveDlg = sal_True;
1041 break;
1043 case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
1044 nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
1045 mbHasPreview = sal_True;
1046 mbHasLink = sal_True;
1048 // aPreviewTimer
1049 maPreViewTimer.SetTimeout( 500 );
1050 maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
1051 break;
1053 case FILEOPEN_PLAY:
1054 nTemplateDescription = TemplateDescription::FILEOPEN_PLAY;
1055 break;
1057 case FILEOPEN_READONLY_VERSION:
1058 nTemplateDescription = TemplateDescription::FILEOPEN_READONLY_VERSION;
1059 mbHasVersions = sal_True;
1060 break;
1062 case FILEOPEN_LINK_PREVIEW:
1063 nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW;
1064 mbHasPreview = sal_True;
1065 mbHasLink = sal_True;
1066 // aPreviewTimer
1067 maPreViewTimer.SetTimeout( 500 );
1068 maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
1069 break;
1071 case FILESAVE_AUTOEXTENSION:
1072 nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION;
1073 mbHasAutoExt = sal_True;
1074 mbIsSaveDlg = sal_True;
1075 break;
1077 default:
1078 DBG_ERRORFILE( "FileDialogHelper::ctor with unknown type" );
1079 break;
1084 //Sequence < Any > aInitArguments( mbSystemPicker || !mpPreferredParentWindow ? 1 : 3 );
1085 Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 );
1087 // This is a hack. We currently know that the internal file picker implementation
1088 // supports the extended arguments as specified below.
1089 // TODO:
1090 // a) adjust the service description so that it includes the TemplateDescription and ParentWindow args
1091 // b) adjust the implementation of the system file picker to that it recognizes it
1092 if ( mbSystemPicker )
1094 aInitArguments[0] <<= nTemplateDescription;
1096 else
1098 aInitArguments[0] <<= NamedValue(
1099 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateDescription" ) ),
1100 makeAny( nTemplateDescription )
1103 ::rtl::OUString sStandardDirTemp = ::rtl::OUString( sStandardDir );
1105 aInitArguments[1] <<= NamedValue(
1106 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StandardDir" ) ),
1107 makeAny( sStandardDirTemp )
1110 aInitArguments[2] <<= NamedValue(
1111 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlackList" ) ),
1112 makeAny( rBlackList )
1116 if ( mpPreferredParentWindow )
1117 aInitArguments[3] <<= NamedValue(
1118 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ),
1119 makeAny( VCLUnoHelper::GetInterface( mpPreferredParentWindow ) )
1127 xInit->initialize( aInitArguments );
1129 catch( const Exception& )
1131 DBG_ERROR( "FileDialogHelper_Impl::FileDialogHelper_Impl: could not initialize the picker!" );
1136 // set multiselection mode
1137 if ( nFlags & SFXWB_MULTISELECTION )
1138 mxFileDlg->setMultiSelectionMode( sal_True );
1140 if ( mbHasLink ) // generate graphic filter only on demand
1141 addGraphicFilter();
1143 // Export dialog
1144 if ( mbExport )
1146 mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) ) ) );
1147 try {
1148 com::sun::star::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW );
1149 xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, sal_True );
1151 catch( const Exception & ) { }
1154 // the "insert file" dialog needs another title
1155 if ( mbInsert )
1157 mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_INSERT ) ) ) );
1158 uno::Reference < XFilePickerControlAccess > xExtDlg( mxFileDlg, UNO_QUERY );
1159 if ( xExtDlg.is() )
1163 xExtDlg->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK,
1164 OUString( String( SfxResId( STR_SFX_EXPLORERFILE_BUTTONINSERT ) ) ) );
1166 catch( IllegalArgumentException ){}
1170 // add the event listener
1171 xNotifier->addFilePickerListener( this );
1174 // ------------------------------------------------------------------------
1175 FileDialogHelper_Impl::~FileDialogHelper_Impl()
1177 // Remove user event if we haven't received it yet
1178 if ( mnPostUserEventId )
1179 Application::RemoveUserEvent( mnPostUserEventId );
1180 mnPostUserEventId = 0;
1182 delete mpGraphicFilter;
1184 if ( mbDeleteMatcher )
1185 delete mpMatcher;
1187 maPreViewTimer.SetTimeoutHdl( Link() );
1189 ::comphelper::disposeComponent( mxFileDlg );
1192 #define nMagic -1
1194 class PickerThread_Impl : public ::vos::OThread
1196 uno::Reference < XFilePicker > mxPicker;
1197 ::vos::OMutex maMutex;
1198 virtual void SAL_CALL run();
1199 sal_Int16 mnRet;
1200 public:
1201 PickerThread_Impl( const uno::Reference < XFilePicker >& rPicker )
1202 : mxPicker( rPicker ), mnRet(nMagic) {}
1204 sal_Int16 GetReturnValue()
1205 { ::vos::OGuard aGuard( maMutex ); return mnRet; }
1207 void SetReturnValue( sal_Int16 aRetValue )
1208 { ::vos::OGuard aGuard( maMutex ); mnRet = aRetValue; }
1211 void SAL_CALL PickerThread_Impl::run()
1215 sal_Int16 n = mxPicker->execute();
1216 SetReturnValue( n );
1218 catch( RuntimeException& )
1220 SetReturnValue( ExecutableDialogResults::CANCEL );
1221 DBG_ERRORFILE( "RuntimeException caught" );
1225 // ------------------------------------------------------------------------
1226 void FileDialogHelper_Impl::setControlHelpIds( const sal_Int16* _pControlId, const sal_Int32* _pHelpId )
1228 DBG_ASSERT( _pControlId && _pHelpId, "FileDialogHelper_Impl::setControlHelpIds: invalid array pointers!" );
1229 if ( !_pControlId || !_pHelpId )
1230 return;
1232 // forward these ids to the file picker
1235 const ::rtl::OUString sHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( "HID:" ) );
1236 // the ids for the single controls
1237 uno::Reference< XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
1238 if ( xControlAccess.is() )
1240 while ( *_pControlId )
1242 // calc the help id of the element
1243 ::rtl::OUString sId( sHelpIdPrefix );
1244 sId += ::rtl::OUString::valueOf( *_pHelpId );
1245 // set the help id
1246 xControlAccess->setValue( *_pControlId, ControlActions::SET_HELP_URL, makeAny( sId ) );
1248 ++_pControlId; ++_pHelpId;
1252 catch( const Exception& )
1254 DBG_ERROR( "FileDialogHelper_Impl::setControlHelpIds: caught an exception while setting the help ids!" );
1258 // ------------------------------------------------------------------------
1259 void FileDialogHelper_Impl::setDialogHelpId( const sal_Int32 _nHelpId )
1261 svt::SetDialogHelpId( mxFileDlg, _nHelpId );
1264 // ------------------------------------------------------------------------
1265 IMPL_LINK( FileDialogHelper_Impl, InitControls, void*, NOTINTERESTEDIN )
1267 (void)NOTINTERESTEDIN;
1268 mnPostUserEventId = 0;
1269 enablePasswordBox( sal_True );
1270 updateFilterOptionsBox( );
1271 updateSelectionBox( );
1273 return 0L;
1276 // ------------------------------------------------------------------------
1277 void FileDialogHelper_Impl::preExecute()
1279 loadConfig( );
1280 setDefaultValues( );
1281 updatePreviewState( sal_False );
1283 implInitializeFileName( );
1284 // #106079# / 2002-12-09 / fs@openoffice.org
1286 #if !(defined(MACOSX) && defined(QUARTZ)) && !defined(WNT)
1287 // allow for dialog implementations which need to be executed before they return valid values for
1288 // current filter and such
1290 // On Vista (at least SP1) it's the same as on MacOSX, the modal dialog won't let message pass
1291 // through before it returns from execution
1292 mnPostUserEventId = Application::PostUserEvent( LINK( this, FileDialogHelper_Impl, InitControls ) );
1293 #else
1294 // However, the Mac OS X implementation's pickers run modally in execute and so the event doesn't
1295 // get through in time... so we call the methods directly
1296 enablePasswordBox( sal_True );
1297 updateFilterOptionsBox( );
1298 updateSelectionBox( );
1299 #endif
1302 // ------------------------------------------------------------------------
1303 void FileDialogHelper_Impl::postExecute( sal_Int16 _nResult )
1305 if ( ExecutableDialogResults::CANCEL != _nResult )
1306 saveConfig();
1309 // ------------------------------------------------------------------------
1310 void FileDialogHelper_Impl::implInitializeFileName( )
1312 if ( maFileName.getLength() )
1314 INetURLObject aObj( maPath );
1315 aObj.Append( maFileName );
1317 // in case we're operating as save dialog, and "auto extension" is checked,
1318 // cut the extension from the name
1319 // #106079# / 2002-12-09 / fs@openoffice.org
1320 if ( mbIsSaveDlg && mbHasAutoExt )
1324 sal_Bool bAutoExtChecked = sal_False;
1326 uno::Reference < XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
1327 if ( xControlAccess.is()
1328 && ( xControlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 )
1329 >>= bAutoExtChecked
1333 if ( bAutoExtChecked )
1334 { // cut the extension
1335 aObj.removeExtension( );
1336 mxFileDlg->setDefaultName( aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
1340 catch( const Exception& )
1342 DBG_ERROR( "FileDialogHelper_Impl::implInitializeFileName: could not ask for the auto-extension current-value!" );
1348 // ------------------------------------------------------------------------
1349 sal_Int16 FileDialogHelper_Impl::implDoExecute()
1351 preExecute();
1353 sal_Int16 nRet = ExecutableDialogResults::CANCEL;
1355 //On MacOSX the native file picker has to run in the primordial thread because of drawing issues
1356 //On Linux the native gtk file picker, when backed by gnome-vfs2, needs to be run in the same
1357 //primordial thread as the ucb gnome-vfs2 provider was initialized in.
1359 #ifdef WNT
1360 if ( mbSystemPicker )
1362 PickerThread_Impl* pThread = new PickerThread_Impl( mxFileDlg );
1363 pThread->create();
1364 while ( pThread->GetReturnValue() == nMagic )
1365 Application::Yield();
1366 pThread->join();
1367 nRet = pThread->GetReturnValue();
1368 delete pThread;
1370 else
1371 #endif
1376 #ifdef WNT
1377 if ( mbSystemPicker )
1379 OReleaseSolarMutex aSolarMutex;
1380 nRet = mxFileDlg->execute();
1382 else
1383 #endif
1384 nRet = mxFileDlg->execute();
1386 catch( const Exception& )
1388 DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
1392 postExecute( nRet );
1394 return nRet;
1397 // ------------------------------------------------------------------------
1398 void FileDialogHelper_Impl::implStartExecute()
1400 DBG_ASSERT( mxFileDlg.is(), "invalid file dialog" );
1402 preExecute();
1404 if ( mbSystemPicker )
1407 else
1411 uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( mxFileDlg, UNO_QUERY );
1412 if ( xAsyncDlg.is() )
1413 xAsyncDlg->startExecuteModal( this );
1415 catch( const Exception& )
1417 DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
1422 // ------------------------------------------------------------------------
1423 String FileDialogHelper_Impl::implEnsureURLExtension(const String& sURL,
1424 const String& /*sExtension*/)
1426 return sURL;
1428 // This feature must be active for file save/export only !
1429 if (
1430 (! mbIsSaveDlg) &&
1431 (! mbExport )
1433 return sURL;
1435 // no extension available (because "ALL *.*" was selected) ?
1436 // Nod idea what else should happen here .-)
1437 if (sExtension.Len() < 1)
1438 return sURL;
1440 // Some FilePicker implementations already add the right extension ...
1441 // or might be the user used the right one already ...
1442 // Dont create duplicate extension.
1443 INetURLObject aURL(sURL);
1444 if (aURL.getExtension().equals(sExtension))
1445 return sURL;
1447 // Ignore any other extension set by the user.
1448 // Make sure suitable extension is used always.
1449 // e.g. "test.bla.odt" for "ODT"
1450 ::rtl::OUStringBuffer sNewURL(256);
1451 sNewURL.append (sURL );
1452 sNewURL.appendAscii("." );
1453 sNewURL.append (sExtension);
1454 return sNewURL.makeStringAndClear();
1458 // ------------------------------------------------------------------------
1459 void lcl_saveLastURLs(SvStringsDtor*& rpURLList ,
1460 ::comphelper::SequenceAsVector< ::rtl::OUString >& lLastURLs )
1462 lLastURLs.clear();
1463 USHORT c = rpURLList->Count();
1464 USHORT i = 0;
1465 for (i=0; i<c; ++i)
1466 lLastURLs.push_back(*(rpURLList->GetObject(i)));
1469 // ------------------------------------------------------------------------
1470 void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker ,
1471 SvStringsDtor*& rpURLList,
1472 const SfxFilter* pFilter )
1474 rpURLList = NULL;
1476 String sExtension;
1477 if (pFilter)
1479 sExtension = pFilter->GetDefaultExtension ();
1480 sExtension.EraseAllChars( '*' );
1481 sExtension.EraseAllChars( '.' );
1484 // a) the new way (optional!)
1485 uno::Reference< XFilePicker2 > xPickNew(xPicker, UNO_QUERY);
1486 if (xPickNew.is())
1488 rpURLList = new SvStringsDtor;
1489 Sequence< OUString > lFiles = xPickNew->getSelectedFiles();
1490 ::sal_Int32 nFiles = lFiles.getLength();
1491 for (::sal_Int32 i = 0; i < nFiles; i++)
1493 String* pURL = new String(implEnsureURLExtension(lFiles[i], sExtension));
1494 rpURLList->Insert( pURL, rpURLList->Count() );
1498 // b) the olde way ... non optional.
1499 else
1501 uno::Reference< XFilePicker > xPickOld(xPicker, UNO_QUERY_THROW);
1502 Sequence< OUString > lFiles = xPickOld->getFiles();
1503 ::sal_Int32 nFiles = lFiles.getLength();
1504 if ( nFiles == 1 )
1506 rpURLList = new SvStringsDtor;
1507 String* pURL = new String(implEnsureURLExtension(lFiles[0], sExtension));
1508 rpURLList->Insert( pURL, 0 );
1510 else
1511 if ( nFiles > 1 )
1513 rpURLList = new SvStringsDtor;
1515 INetURLObject aPath( lFiles[0] );
1516 aPath.setFinalSlash();
1518 for (::sal_Int32 i = 1; i < nFiles; i++)
1520 if (i == 1)
1521 aPath.Append( lFiles[i] );
1522 else
1523 aPath.setName( lFiles[i] );
1525 String* pURL = new String(implEnsureURLExtension(aPath.GetMainURL( INetURLObject::NO_DECODE ), sExtension) );
1526 rpURLList->Insert( pURL, rpURLList->Count() );
1531 lcl_saveLastURLs(rpURLList, mlLastURLs);
1534 // ------------------------------------------------------------------------
1535 ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
1536 SfxItemSet *& rpSet,
1537 String& rFilter )
1539 // rFilter is a pure output parameter, it shouldn't be used for anything else
1540 // changing this would surely break code
1541 // rpSet is in/out parameter, usually just a media-descriptor that can be changed by dialog
1543 uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
1545 // retrieves parameters from rpSet
1546 // for now only Password is used
1547 if ( rpSet )
1549 // check password checkbox if the document had password before
1550 if( mbHasPassword )
1552 SFX_ITEMSET_ARG( rpSet, pPassItem, SfxStringItem, SID_PASSWORD, FALSE );
1553 mbPwdCheckBoxState = ( pPassItem != NULL );
1556 SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, FALSE );
1557 if ( pSelectItem )
1558 mbSelection = pSelectItem->GetValue();
1559 else
1560 mbSelectionEnabled = sal_False;
1562 // the password will be set in case user decide so
1563 rpSet->ClearItem( SID_PASSWORD );
1566 if ( mbHasPassword && !mbPwdCheckBoxState )
1568 SvtSecurityOptions aSecOpt;
1569 mbPwdCheckBoxState = (
1570 aSecOpt.IsOptionSet( SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD ) );
1573 rpURLList = NULL;
1575 if ( ! mxFileDlg.is() )
1576 return ERRCODE_ABORT;
1578 if ( ExecutableDialogResults::CANCEL != implDoExecute() )
1580 // create an itemset if there is no
1581 if( !rpSet )
1582 rpSet = new SfxAllItemSet( SFX_APP()->GetPool() );
1584 // the item should remain only if it was set by the dialog
1585 rpSet->ClearItem( SID_SELECTION );
1587 if( mbExport )
1591 Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
1592 sal_Bool bSelection = sal_False;
1593 if ( aValue >>= bSelection )
1594 rpSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
1596 catch( IllegalArgumentException )
1598 DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
1603 // set the read-only flag. When inserting a file, this flag is always set
1604 if ( mbInsert )
1605 rpSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
1606 else
1608 if ( ( FILEOPEN_READONLY_VERSION == m_nDialogType ) && xCtrlAccess.is() )
1612 Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
1613 sal_Bool bReadOnly = sal_False;
1614 if ( ( aValue >>= bReadOnly ) && bReadOnly )
1615 rpSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
1617 catch( IllegalArgumentException )
1619 DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
1623 if ( mbHasVersions && xCtrlAccess.is() )
1627 Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
1628 ControlActions::GET_SELECTED_ITEM_INDEX );
1629 sal_Int32 nVersion = 0;
1630 if ( ( aValue >>= nVersion ) && nVersion > 0 )
1631 // open a special version; 0 == current version
1632 rpSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) );
1634 catch( IllegalArgumentException ){}
1637 // set the filter
1638 getRealFilter( rFilter );
1640 // fill the rpURLList
1641 implGetAndCacheFiles(mxFileDlg, rpURLList, getCurentSfxFilter());
1642 if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL )
1643 return ERRCODE_ABORT;
1645 // check, wether or not we have to display a password box
1646 if ( mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() )
1650 Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
1651 sal_Bool bPassWord = sal_False;
1652 if ( ( aValue >>= bPassWord ) && bPassWord )
1654 // ask for a password
1655 uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
1657 if( xInteractionHandler.is() )
1659 // TODO: need a save way to distinguish MS filters from other filters
1660 bool bMSType = CheckMSPasswordCapabilityForExport( rFilter );
1661 ::comphelper::DocPasswordRequestType eType = bMSType ?
1662 ::comphelper::DocPasswordRequestType_MS :
1663 ::comphelper::DocPasswordRequestType_STANDARD;
1665 ::comphelper::DocPasswordRequest* pPasswordRequest = new ::comphelper::DocPasswordRequest(
1666 eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)) );
1668 uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest );
1669 xInteractionHandler->handle( rRequest );
1670 if ( pPasswordRequest->isPassword() )
1671 rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) );
1672 else
1673 return ERRCODE_ABORT;
1677 catch( IllegalArgumentException ){}
1680 SaveLastUsedFilter();
1681 return ERRCODE_NONE;
1683 else
1684 return ERRCODE_ABORT;
1687 // ------------------------------------------------------------------------
1688 ErrCode FileDialogHelper_Impl::execute()
1690 if ( ! mxFileDlg.is() )
1691 return ERRCODE_ABORT;
1693 sal_Int16 nRet = implDoExecute();
1695 maPath = mxFileDlg->getDisplayDirectory();
1697 if ( ExecutableDialogResults::CANCEL == nRet )
1698 return ERRCODE_ABORT;
1699 else
1701 return ERRCODE_NONE;
1705 // ------------------------------------------------------------------------
1706 OUString FileDialogHelper_Impl::getPath() const
1708 OUString aPath;
1710 if ( mxFileDlg.is() )
1711 aPath = mxFileDlg->getDisplayDirectory();
1713 if ( !aPath.getLength() )
1714 aPath = maPath;
1716 return aPath;
1719 // ------------------------------------------------------------------------
1720 OUString FileDialogHelper_Impl::getFilter() const
1722 String aFilter = getCurrentFilterUIName();
1724 if( !aFilter.Len() )
1725 aFilter = maCurFilter;
1727 return aFilter;
1730 // ------------------------------------------------------------------------
1731 void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
1733 _rFilter = getCurrentFilterUIName();
1735 if ( !_rFilter.Len() )
1736 _rFilter = maCurFilter;
1738 if ( _rFilter.Len() && mpMatcher )
1740 const SfxFilter* pFilter =
1741 mpMatcher->GetFilter4UIName( _rFilter, m_nMustFlags, m_nDontFlags );
1742 _rFilter = pFilter ? pFilter->GetFilterName() : _rFilter.Erase();
1746 // ------------------------------------------------------------------------
1747 void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
1749 if ( ! _rPath.getLength() )
1750 // nothing to do
1751 return;
1754 if ( !::utl::UCBContentHelper::IsFolder( _rPath ) )
1755 // only valid folders accepted here
1756 return;
1759 maPath = _rPath;
1760 if ( mxFileDlg.is() )
1764 mxFileDlg->setDisplayDirectory( maPath );
1766 catch( const IllegalArgumentException& )
1768 DBG_ERROR( "FileDialogHelper_Impl::displayFolder: caught an exception!" );
1773 // ------------------------------------------------------------------------
1774 void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile )
1776 maFileName = _rFile;
1777 if ( mxFileDlg.is() )
1781 mxFileDlg->setDefaultName( maFileName );
1783 catch( const IllegalArgumentException& )
1785 DBG_ERROR( "FileDialogHelper_Impl::setFileName: caught an exception!" );
1790 // ------------------------------------------------------------------------
1791 void FileDialogHelper_Impl::setFilter( const OUString& rFilter )
1793 DBG_ASSERT( rFilter.indexOf(':') == -1, "Old filter name used!");
1795 maCurFilter = rFilter;
1797 if ( rFilter.getLength() && mpMatcher )
1799 const SfxFilter* pFilter = mpMatcher->GetFilter4FilterName(
1800 rFilter, m_nMustFlags, m_nDontFlags );
1801 if ( pFilter )
1802 maCurFilter = pFilter->GetUIName();
1805 uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1807 if ( maCurFilter.getLength() && xFltMgr.is() )
1811 xFltMgr->setCurrentFilter( maCurFilter );
1813 catch( IllegalArgumentException ){}
1817 // ------------------------------------------------------------------------
1818 void FileDialogHelper_Impl::createMatcher( const String& rFactory )
1820 mpMatcher = new SfxFilterMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
1821 mbDeleteMatcher = sal_True;
1824 // ------------------------------------------------------------------------
1825 void FileDialogHelper_Impl::addFilters( sal_Int64 nFlags,
1826 const String& rFactory,
1827 SfxFilterFlags nMust,
1828 SfxFilterFlags nDont )
1830 uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1832 if ( ! xFltMgr.is() )
1833 return;
1835 // we still need a matcher to convert UI names to filter names
1836 if ( !rFactory.Len() )
1838 SfxApplication *pSfxApp = SFX_APP();
1839 mpMatcher = &pSfxApp->GetFilterMatcher();
1840 mbDeleteMatcher = sal_False;
1842 else
1844 mpMatcher = new SfxFilterMatcher( rFactory );
1845 mbDeleteMatcher = sal_True;
1848 uno::Reference< XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
1849 uno::Reference< XContainerQuery > xFilterCont(
1850 xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory")),
1851 UNO_QUERY);
1852 if ( ! xFilterCont.is() )
1853 return;
1855 m_nMustFlags |= nMust;
1856 m_nDontFlags |= nDont;
1858 // create the list of filters
1859 ::rtl::OUStringBuffer sQuery(256);
1860 sQuery.appendAscii("getSortedFilterList()");
1861 sQuery.appendAscii(":module=" );
1862 sQuery.append (rFactory ); // use long name here !
1863 sQuery.appendAscii(":iflags=" );
1864 sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nMustFlags));
1865 sQuery.appendAscii(":eflags=" );
1866 sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nDontFlags));
1868 uno::Reference< XEnumeration > xResult = xFilterCont->createSubSetEnumerationByQuery(sQuery.makeStringAndClear());
1869 TSortedFilterList aIter (xResult);
1871 // no matcher any longer used ...
1872 mbDeleteMatcher = sal_False;
1874 // append the filters
1875 ::rtl::OUString sFirstFilter;
1876 if ( WB_OPEN == ( nFlags & WB_OPEN ) )
1877 ::sfx2::appendFiltersForOpen( aIter, xFltMgr, sFirstFilter, *this );
1878 else if ( mbExport )
1879 ::sfx2::appendExportFilters( aIter, xFltMgr, sFirstFilter, *this );
1880 else
1881 ::sfx2::appendFiltersForSave( aIter, xFltMgr, sFirstFilter, *this, rFactory );
1883 // set our initial selected filter (if we do not already have one)
1884 if ( !maSelectFilter.getLength() )
1885 maSelectFilter = sFirstFilter;
1888 // ------------------------------------------------------------------------
1889 void FileDialogHelper_Impl::addFilter( const OUString& rFilterName,
1890 const OUString& rExtension )
1892 uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1894 if ( ! xFltMgr.is() )
1895 return;
1899 xFltMgr->appendFilter( rFilterName, rExtension );
1901 if ( !maSelectFilter.getLength() )
1902 maSelectFilter = rFilterName;
1904 catch( IllegalArgumentException )
1906 #ifdef DBG_UTIL
1907 ByteString aMsg( "Could not append Filter" );
1908 aMsg += ByteString( String( rFilterName ), RTL_TEXTENCODING_UTF8 );
1909 DBG_ERRORFILE( aMsg.GetBuffer() );
1910 #endif
1914 // ------------------------------------------------------------------------
1915 void FileDialogHelper_Impl::addGraphicFilter()
1917 uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1919 if ( ! xFltMgr.is() )
1920 return;
1922 // create the list of filters
1923 mpGraphicFilter = new GraphicFilter;
1924 USHORT i, j, nCount = mpGraphicFilter->GetImportFormatCount();
1926 // compute the extension string for all known import filters
1927 String aExtensions;
1929 for ( i = 0; i < nCount; i++ )
1931 j = 0;
1932 String sWildcard;
1933 while( TRUE )
1935 sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
1936 if ( !sWildcard.Len() )
1937 break;
1938 if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
1940 if ( aExtensions.Len() )
1941 aExtensions += sal_Unicode(';');
1942 aExtensions += sWildcard;
1947 #if defined(WIN) || defined(WNT)
1948 if ( aExtensions.Len() > 240 )
1949 aExtensions = DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL );
1950 #endif
1951 sal_Bool bIsInOpenMode = isInOpenMode();
1955 OUString aAllFilterName = String( SfxResId( STR_SFX_IMPORT_ALL ) );
1956 aAllFilterName = ::sfx2::addExtension( aAllFilterName, aExtensions, bIsInOpenMode, *this );
1958 xFltMgr->appendFilter( aAllFilterName, aExtensions );
1959 maSelectFilter = aAllFilterName;
1961 catch( IllegalArgumentException )
1963 DBG_ERRORFILE( "Could not append Filter" );
1966 // Now add the filter
1967 for ( i = 0; i < nCount; i++ )
1969 String aName = mpGraphicFilter->GetImportFormatName( i );
1970 String aExt;
1971 j = 0;
1972 String sWildcard;
1973 while( TRUE )
1975 sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
1976 if ( !sWildcard.Len() )
1977 break;
1978 if ( aExt.Search( sWildcard ) == STRING_NOTFOUND )
1980 if ( aExt.Len() )
1981 aExt += sal_Unicode(';');
1982 aExt += sWildcard;
1985 aName = ::sfx2::addExtension( aName, aExt, bIsInOpenMode, *this );
1988 xFltMgr->appendFilter( aName, aExt );
1990 catch( IllegalArgumentException )
1992 DBG_ERRORFILE( "Could not append Filter" );
1997 // ------------------------------------------------------------------------
1998 #define GRF_CONFIG_STR " "
1999 #define STD_CONFIG_STR "1 "
2001 void FileDialogHelper_Impl::saveConfig()
2003 uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
2004 Any aValue;
2006 if ( ! xDlg.is() )
2007 return;
2009 if ( mbHasPreview )
2011 SvtViewOptions aDlgOpt( E_DIALOG, IMPGRF_CONFIGNAME );
2012 String aUserData = DEFINE_CONST_UNICODE( GRF_CONFIG_STR );
2016 sal_Bool bValue = sal_False;
2017 aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
2018 bValue = sal_False;
2019 aValue >>= bValue;
2020 aUserData.SetToken( 1, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
2022 INetURLObject aObj( getPath() );
2024 if ( aObj.GetProtocol() == INET_PROT_FILE )
2025 aUserData.SetToken( 2, ' ', aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2027 String aFilter = getFilter();
2028 aFilter = EncodeSpaces_Impl( aFilter );
2029 aUserData.SetToken( 3, ' ', aFilter );
2031 aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
2033 catch( IllegalArgumentException ){}
2035 else
2037 sal_Bool bWriteConfig = sal_False;
2038 SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
2039 String aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
2041 if ( aDlgOpt.Exists() )
2043 Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
2044 OUString aTemp;
2045 if ( aUserItem >>= aTemp )
2046 aUserData = String( aTemp );
2049 if ( mbHasAutoExt )
2053 aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 );
2054 sal_Bool bAutoExt = sal_True;
2055 aValue >>= bAutoExt;
2056 aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bAutoExt ) );
2057 bWriteConfig = sal_True;
2059 catch( IllegalArgumentException ){}
2062 if ( ! mbIsSaveDlg )
2064 OUString aPath = getPath();
2065 if ( aPath.getLength() &&
2066 utl::LocalFileHelper::IsLocalFile( aPath ) )
2068 aUserData.SetToken( 1, ' ', aPath );
2069 bWriteConfig = sal_True;
2073 if ( bWriteConfig )
2074 aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
2077 SfxApplication *pSfxApp = SFX_APP();
2078 pSfxApp->SetLastDir_Impl( getPath() );
2081 // ------------------------------------------------------------------------
2082 namespace
2084 static ::rtl::OUString getInitPath( const String& _rFallback, const xub_StrLen _nFallbackToken )
2086 SfxApplication *pSfxApp = SFX_APP();
2087 String sPath = pSfxApp->GetLastDir_Impl();
2089 if ( !sPath.Len() )
2090 sPath = _rFallback.GetToken( _nFallbackToken, ' ' );
2092 // check if the path points to a valid (accessible) directory
2093 sal_Bool bValid = sal_False;
2094 if ( sPath.Len() )
2096 String sPathCheck( sPath );
2097 if ( sPathCheck.GetBuffer()[ sPathCheck.Len() - 1 ] != '/' )
2098 sPathCheck += '/';
2099 sPathCheck += '.';
2102 ::ucbhelper::Content aContent( sPathCheck, uno::Reference< ucb::XCommandEnvironment >() );
2103 bValid = aContent.isFolder();
2105 catch( Exception& ) {}
2108 if ( !bValid )
2109 sPath.Erase();
2111 return sPath;
2115 // ------------------------------------------------------------------------
2116 void FileDialogHelper_Impl::loadConfig()
2118 uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
2119 Any aValue;
2121 if ( ! xDlg.is() )
2122 return;
2124 if ( mbHasPreview )
2126 SvtViewOptions aViewOpt( E_DIALOG, IMPGRF_CONFIGNAME );
2127 String aUserData;
2129 if ( aViewOpt.Exists() )
2131 Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2132 OUString aTemp;
2133 if ( aUserItem >>= aTemp )
2134 aUserData = String( aTemp );
2137 if ( aUserData.Len() > 0 )
2141 // respect the last "show preview" state
2142 sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32();
2143 if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ).hasValue() )
2145 aValue <<= bShowPreview;
2146 xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
2149 if ( !maPath.getLength() )
2150 displayFolder( getInitPath( aUserData, 2 ) );
2152 if ( ! maCurFilter.getLength() )
2154 String aFilter = aUserData.GetToken( 3, ' ' );
2155 aFilter = DecodeSpaces_Impl( aFilter );
2156 setFilter( aFilter );
2159 // set the member so we know that we have to show the preview
2160 mbShowPreview = bShowPreview;
2162 catch( IllegalArgumentException ){}
2165 if ( !maPath.getLength() )
2166 displayFolder( SvtPathOptions().GetGraphicPath() );
2168 else
2170 SvtViewOptions aViewOpt( E_DIALOG, IODLG_CONFIGNAME );
2171 String aUserData;
2173 if ( aViewOpt.Exists() )
2175 Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2176 OUString aTemp;
2177 if ( aUserItem >>= aTemp )
2178 aUserData = String( aTemp );
2181 if ( ! aUserData.Len() )
2182 aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
2184 if ( ! maPath.getLength() )
2185 displayFolder( getInitPath( aUserData, 1 ) );
2187 if ( mbHasAutoExt )
2189 sal_Int32 nFlag = aUserData.GetToken( 0, ' ' ).ToInt32();
2190 aValue <<= (sal_Bool) nFlag;
2193 xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
2195 catch( IllegalArgumentException ){}
2198 if ( !maPath.getLength() )
2199 displayFolder( SvtPathOptions().GetWorkPath() );
2203 // ------------------------------------------------------------------------
2204 void FileDialogHelper_Impl::setDefaultValues()
2206 // when no filter is set, we set the curentFilter to <all>
2207 if ( !maCurFilter.getLength() && maSelectFilter.getLength() )
2209 uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
2212 xFltMgr->setCurrentFilter( maSelectFilter );
2214 catch( IllegalArgumentException )
2218 // when no path is set, we use the standard 'work' folder
2219 if ( ! maPath.getLength() )
2221 OUString aWorkFolder = SvtPathOptions().GetWorkPath();
2224 mxFileDlg->setDisplayDirectory( aWorkFolder );
2226 catch( const Exception& )
2228 DBG_ERROR( "FileDialogHelper_Impl::setDefaultValues: caught an exception while setting the display directory!" );
2231 // INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
2232 //SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
2236 sal_Bool FileDialogHelper_Impl::isShowFilterExtensionEnabled() const
2238 return !maFilters.empty();
2241 void FileDialogHelper_Impl::addFilterPair( const OUString& rFilter,
2242 const OUString& rFilterWithExtension )
2244 maFilters.push_back( FilterPair( rFilter, rFilterWithExtension ) );
2248 OUString FileDialogHelper_Impl::getFilterName( const OUString& rFilterWithExtension ) const
2250 OUString sRet;
2251 for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
2253 if ( (*pIter).Second == rFilterWithExtension )
2255 sRet = (*pIter).First;
2256 break;
2259 return sRet;
2262 OUString FileDialogHelper_Impl::getFilterWithExtension( const OUString& rFilter ) const
2264 OUString sRet;
2265 for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
2267 if ( (*pIter).First == rFilter )
2269 sRet = (*pIter).Second;
2270 break;
2273 return sRet;
2276 void FileDialogHelper_Impl::SetContext( FileDialogHelper::Context _eNewContext )
2278 meContext = _eNewContext;
2280 sal_Int32 nNewHelpId = 0;
2281 OUString aConfigId;
2283 switch( _eNewContext )
2285 // #104952# dependency to SVX not allowed! When used again, another solution has to be found
2286 // case FileDialogHelper::SW_INSERT_GRAPHIC:
2287 // case FileDialogHelper::SC_INSERT_GRAPHIC:
2288 // case FileDialogHelper::SD_INSERT_GRAPHIC: nNewHelpId = SID_INSERT_GRAPHIC; break;
2289 case FileDialogHelper::SW_INSERT_SOUND:
2290 case FileDialogHelper::SC_INSERT_SOUND:
2291 case FileDialogHelper::SD_INSERT_SOUND: nNewHelpId = SID_INSERT_SOUND; break;
2292 case FileDialogHelper::SW_INSERT_VIDEO:
2293 case FileDialogHelper::SC_INSERT_VIDEO:
2294 case FileDialogHelper::SD_INSERT_VIDEO: nNewHelpId = SID_INSERT_VIDEO; break;
2295 default: break;
2298 const OUString* pConfigId = GetLastFilterConfigId( _eNewContext );
2299 if( pConfigId )
2300 LoadLastUsedFilter( *pConfigId );
2302 // if( nNewHelpId )
2303 // this->setDialogHelpId( nNewHelpId );
2306 // ------------------------------------------------------------------------
2307 // ----------- FileDialogHelper ---------------------------
2308 // ------------------------------------------------------------------------
2310 FileDialogHelper::FileDialogHelper(
2311 sal_Int64 nFlags,
2312 const String& rFact,
2313 SfxFilterFlags nMust,
2314 SfxFilterFlags nDont )
2316 mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags );
2317 mxImp = mpImp;
2319 // create the list of filters
2320 mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2323 FileDialogHelper::FileDialogHelper(
2324 sal_Int64 nFlags,
2325 const String& rFact,
2326 sal_Int16 nDialog,
2327 SfxFilterFlags nMust,
2328 SfxFilterFlags nDont,
2329 const String& rStandardDir,
2330 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
2332 mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog, NULL , rStandardDir, rBlackList );
2333 mxImp = mpImp;
2335 // create the list of filters
2336 mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2339 FileDialogHelper::FileDialogHelper(
2340 sal_Int64 nFlags,
2341 const String& rFact,
2342 sal_Int16 nDialog,
2343 SfxFilterFlags nMust,
2344 SfxFilterFlags nDont )
2346 mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog );
2347 mxImp = mpImp;
2349 // create the list of filters
2350 mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2353 // ------------------------------------------------------------------------
2354 FileDialogHelper::FileDialogHelper( sal_Int64 nFlags )
2356 sal_Int16 nDialogType = getDialogType( nFlags );
2358 mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
2359 mxImp = mpImp;
2362 // ------------------------------------------------------------------------
2363 FileDialogHelper::FileDialogHelper(
2364 sal_Int16 nDialogType,
2365 sal_Int64 nFlags,
2366 const String& rFact,
2367 SfxFilterFlags nMust,
2368 SfxFilterFlags nDont )
2370 mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
2371 mxImp = mpImp;
2373 // create the list of filters
2374 mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2377 // ------------------------------------------------------------------------
2378 FileDialogHelper::FileDialogHelper(
2379 sal_Int16 nDialogType,
2380 sal_Int64 nFlags,
2381 const String& rFact,
2382 sal_Int16 nDialog,
2383 SfxFilterFlags nMust,
2384 SfxFilterFlags nDont,
2385 const String& rStandardDir,
2386 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
2388 mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, nDialog, NULL, rStandardDir, rBlackList );
2389 mxImp = mpImp;
2391 // create the list of filters
2392 mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2395 // ------------------------------------------------------------------------
2396 FileDialogHelper::FileDialogHelper(
2397 sal_Int16 nDialogType,
2398 sal_Int64 nFlags,
2399 Window* _pPreferredParent )
2401 mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent );
2402 mxImp = mpImp;
2405 // ------------------------------------------------------------------------
2406 FileDialogHelper::FileDialogHelper(
2407 sal_Int16 nDialogType,
2408 sal_Int64 nFlags,
2409 const ::rtl::OUString& aFilterUIName,
2410 const ::rtl::OUString& aExtName,
2411 const ::rtl::OUString& rStandardDir,
2412 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList,
2413 Window* _pPreferredParent )
2415 mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent,rStandardDir, rBlackList );
2416 mxImp = mpImp;
2418 // the wildcard here is expected in form "*.extension"
2419 ::rtl::OUString aWildcard;
2420 if ( aExtName.indexOf( (sal_Unicode)'*' ) != 0 )
2422 if ( aExtName.getLength() && aExtName.indexOf( (sal_Unicode)'.' ) != 0 )
2423 aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
2424 else
2425 aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*" ) );
2428 aWildcard += aExtName;
2430 ::rtl::OUString aUIString =
2431 ::sfx2::addExtension( aFilterUIName, aWildcard, ( WB_OPEN == ( nFlags & WB_OPEN ) ), *mpImp );
2432 AddFilter( aUIString, aWildcard );
2435 // ------------------------------------------------------------------------
2436 FileDialogHelper::~FileDialogHelper()
2438 mpImp->dispose();
2439 mxImp.clear();
2442 // ------------------------------------------------------------------------
2443 void FileDialogHelper::CreateMatcher( const String& rFactory )
2445 mpImp->createMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
2448 // ------------------------------------------------------------------------
2449 void FileDialogHelper::SetControlHelpIds( const sal_Int16* _pControlId, const sal_Int32* _pHelpId )
2451 mpImp->setControlHelpIds( _pControlId, _pHelpId );
2454 // ------------------------------------------------------------------------
2455 void FileDialogHelper::SetDialogHelpId( const sal_Int32 _nHelpId )
2457 mpImp->setDialogHelpId( _nHelpId );
2460 void FileDialogHelper::SetContext( Context _eNewContext )
2462 mpImp->SetContext( _eNewContext );
2465 // ------------------------------------------------------------------------
2466 IMPL_LINK( FileDialogHelper, ExecuteSystemFilePicker, void*, EMPTYARG )
2468 m_nError = mpImp->execute();
2469 if ( m_aDialogClosedLink.IsSet() )
2470 m_aDialogClosedLink.Call( this );
2472 return 0L;
2475 // ------------------------------------------------------------------------
2476 // rDirPath has to be a directory
2477 ErrCode FileDialogHelper::Execute( SvStringsDtor*& rpURLList,
2478 SfxItemSet *& rpSet,
2479 String& rFilter,
2480 const String& rDirPath )
2482 SetDisplayFolder( rDirPath );
2483 return mpImp->execute( rpURLList, rpSet, rFilter );
2487 // ------------------------------------------------------------------------
2488 ErrCode FileDialogHelper::Execute()
2490 return mpImp->execute();
2493 // ------------------------------------------------------------------------
2494 ErrCode FileDialogHelper::Execute( SfxItemSet *& rpSet,
2495 String& rFilter )
2497 ErrCode nRet;
2498 SvStringsDtor* pURLList;
2500 nRet = mpImp->execute( pURLList, rpSet, rFilter );
2502 delete pURLList;
2504 return nRet;
2507 void FileDialogHelper::StartExecuteModal( const Link& rEndDialogHdl )
2509 m_aDialogClosedLink = rEndDialogHdl;
2510 m_nError = ERRCODE_NONE;
2511 if ( mpImp->isSystemFilePicker() )
2512 Application::PostUserEvent( LINK( this, FileDialogHelper, ExecuteSystemFilePicker ) );
2513 else
2514 mpImp->implStartExecute();
2517 // ------------------------------------------------------------------------
2519 short FileDialogHelper::GetDialogType() const
2521 return mpImp ? mpImp->m_nDialogType : 0;
2524 // ------------------------------------------------------------------------
2526 sal_Bool FileDialogHelper::IsPasswordEnabled() const
2528 return mpImp ? mpImp->isPasswordEnabled() : sal_False;
2531 // ------------------------------------------------------------------------
2533 String FileDialogHelper::GetRealFilter() const
2535 String sFilter;
2536 if ( mpImp )
2537 mpImp->getRealFilter( sFilter );
2538 return sFilter;
2541 // ------------------------------------------------------------------------
2542 void FileDialogHelper::SetTitle( const String& rNewTitle )
2544 if ( mpImp->mxFileDlg.is() )
2545 mpImp->mxFileDlg->setTitle( rNewTitle );
2548 // ------------------------------------------------------------------------
2549 String FileDialogHelper::GetPath() const
2551 OUString aPath;
2553 if ( mpImp->mlLastURLs.size() > 0)
2554 return mpImp->mlLastURLs[0];
2556 if ( mpImp->mxFileDlg.is() )
2558 Sequence < OUString > aPathSeq = mpImp->mxFileDlg->getFiles();
2560 if ( aPathSeq.getLength() == 1 )
2562 aPath = aPathSeq[0];
2566 return aPath;
2569 // ------------------------------------------------------------------------
2570 Sequence < OUString > FileDialogHelper::GetMPath() const
2572 if ( mpImp->mlLastURLs.size() > 0)
2573 return mpImp->mlLastURLs.getAsConstList();
2575 if ( mpImp->mxFileDlg.is() )
2576 return mpImp->mxFileDlg->getFiles();
2577 else
2579 Sequence < OUString > aEmpty;
2580 return aEmpty;
2584 // ------------------------------------------------------------------------
2585 Sequence< ::rtl::OUString > FileDialogHelper::GetSelectedFiles() const
2587 // a) the new way (optional!)
2588 uno::Sequence< ::rtl::OUString > aResultSeq;
2589 uno::Reference< XFilePicker2 > xPickNew(mpImp->mxFileDlg, UNO_QUERY);
2590 if (xPickNew.is())
2592 aResultSeq = xPickNew->getSelectedFiles();
2594 // b) the olde way ... non optional.
2595 else
2597 uno::Reference< XFilePicker > xPickOld(mpImp->mxFileDlg, UNO_QUERY_THROW);
2598 Sequence< OUString > lFiles = xPickOld->getFiles();
2599 ::sal_Int32 nFiles = lFiles.getLength();
2600 if ( nFiles > 1 )
2602 aResultSeq = Sequence< ::rtl::OUString >( nFiles-1 );
2604 INetURLObject aPath( lFiles[0] );
2605 aPath.setFinalSlash();
2607 for (::sal_Int32 i = 1; i < nFiles; i++)
2609 if (i == 1)
2610 aPath.Append( lFiles[i] );
2611 else
2612 aPath.setName( lFiles[i] );
2614 aResultSeq[i-1] = ::rtl::OUString(aPath.GetMainURL( INetURLObject::NO_DECODE ));
2617 else
2618 aResultSeq = lFiles;
2621 return aResultSeq;
2624 // ------------------------------------------------------------------------
2625 String FileDialogHelper::GetDisplayDirectory() const
2627 return mpImp->getPath();
2630 // ------------------------------------------------------------------------
2631 String FileDialogHelper::GetCurrentFilter() const
2633 return mpImp->getFilter();
2636 // ------------------------------------------------------------------------
2637 ErrCode FileDialogHelper::GetGraphic( Graphic& rGraphic ) const
2639 return mpImp->getGraphic( rGraphic );
2642 // ------------------------------------------------------------------------
2643 static int impl_isFolder( const OUString& rPath )
2645 uno::Reference< task::XInteractionHandler > xHandler;
2648 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
2649 xHandler.set( xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.task.InteractionHandler" ) ),
2650 uno::UNO_QUERY_THROW );
2652 catch ( Exception const & )
2658 ::ucbhelper::Content aContent(
2659 rPath, new ::ucbhelper::CommandEnvironment( xHandler, uno::Reference< ucb::XProgressHandler >() ) );
2660 if ( aContent.isFolder() )
2661 return 1;
2663 return 0;
2665 catch ( Exception const & )
2669 return -1;
2672 void FileDialogHelper::SetDisplayDirectory( const String& _rPath )
2674 if ( !_rPath.Len() )
2675 return;
2677 // if the given path isn't a folder, we cut off the last part
2678 // and take it as filename and the rest of the path should be
2679 // the folder
2681 INetURLObject aObj( _rPath );
2683 ::rtl::OUString sFileName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
2684 aObj.removeSegment();
2685 ::rtl::OUString sPath = aObj.GetMainURL( INetURLObject::NO_DECODE );
2687 int nIsFolder = impl_isFolder( _rPath );
2688 if ( nIsFolder == 0 ||
2689 ( nIsFolder == -1 && impl_isFolder( sPath ) == 1 ) )
2691 mpImp->setFileName( sFileName );
2692 mpImp->displayFolder( sPath );
2694 else
2696 INetURLObject aObjPathName( _rPath );
2697 ::rtl::OUString sFolder( aObjPathName.GetMainURL( INetURLObject::NO_DECODE ) );
2698 if ( sFolder.getLength() == 0 )
2700 // _rPath is not a valid path -> fallback to home directory
2701 NAMESPACE_VOS( OSecurity ) aSecurity;
2702 aSecurity.getHomeDir( sFolder );
2704 mpImp->displayFolder( sFolder );
2708 // ------------------------------------------------------------------------
2709 void FileDialogHelper::SetDisplayFolder( const String& _rURL )
2711 mpImp->displayFolder( _rURL );
2714 // ------------------------------------------------------------------------
2715 void FileDialogHelper::SetFileName( const String& _rFileName )
2717 mpImp->setFileName( _rFileName );
2720 // ------------------------------------------------------------------------
2721 void FileDialogHelper::AddFilter( const String& rFilterName,
2722 const String& rExtension )
2724 mpImp->addFilter( rFilterName, rExtension );
2727 // ------------------------------------------------------------------------
2728 void FileDialogHelper::SetCurrentFilter( const String& rFilter )
2730 String sFilter( rFilter );
2731 if ( mpImp->isShowFilterExtensionEnabled() )
2732 sFilter = mpImp->getFilterWithExtension( rFilter );
2733 mpImp->setFilter( sFilter );
2736 // ------------------------------------------------------------------------
2737 uno::Reference < XFilePicker > FileDialogHelper::GetFilePicker() const
2739 return mpImp->mxFileDlg;
2742 // ------------------------------------------------------------------------
2743 sal_Int16 FileDialogHelper::getDialogType( sal_Int64 nFlags ) const
2745 sal_Int16 nDialogType = FILEOPEN_SIMPLE;
2747 if ( nFlags & WB_SAVEAS )
2749 if ( nFlags & SFXWB_PASSWORD )
2750 nDialogType = FILESAVE_AUTOEXTENSION_PASSWORD;
2751 else
2752 nDialogType = FILESAVE_SIMPLE;
2754 else if ( nFlags & SFXWB_GRAPHIC )
2756 if ( nFlags & SFXWB_SHOWSTYLES )
2757 nDialogType = FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
2758 else
2759 nDialogType = FILEOPEN_LINK_PREVIEW;
2761 else if ( SFXWB_INSERT != ( nFlags & SFXWB_INSERT ) )
2762 nDialogType = FILEOPEN_READONLY_VERSION;
2764 return nDialogType;
2767 // ------------------------------------------------------------------------
2768 // XFilePickerListener Methods
2769 // ------------------------------------------------------------------------
2770 void SAL_CALL FileDialogHelper::FileSelectionChanged( const FilePickerEvent& aEvent )
2772 mpImp->handleFileSelectionChanged( aEvent );
2775 // ------------------------------------------------------------------------
2776 void SAL_CALL FileDialogHelper::DirectoryChanged( const FilePickerEvent& aEvent )
2778 mpImp->handleDirectoryChanged( aEvent );
2781 // ------------------------------------------------------------------------
2782 OUString SAL_CALL FileDialogHelper::HelpRequested( const FilePickerEvent& aEvent )
2784 return mpImp->handleHelpRequested( aEvent );
2787 // ------------------------------------------------------------------------
2788 void SAL_CALL FileDialogHelper::ControlStateChanged( const FilePickerEvent& aEvent )
2790 mpImp->handleControlStateChanged( aEvent );
2793 // ------------------------------------------------------------------------
2794 void SAL_CALL FileDialogHelper::DialogSizeChanged()
2796 mpImp->handleDialogSizeChanged();
2799 // ------------------------------------------------------------------------
2800 void SAL_CALL FileDialogHelper::DialogClosed( const DialogClosedEvent& _rEvent )
2802 m_nError = ( RET_OK == _rEvent.DialogResult ) ? ERRCODE_NONE : ERRCODE_ABORT;
2803 if ( m_aDialogClosedLink.IsSet() )
2804 m_aDialogClosedLink.Call( this );
2807 // ------------------------------------------------------------------------
2808 // ------------------------------------------------------------------------
2809 // ------------------------------------------------------------------------
2811 ErrCode FileOpenDialog_Impl( sal_Int64 nFlags,
2812 const String& rFact,
2813 SvStringsDtor *& rpURLList,
2814 String& rFilter,
2815 SfxItemSet *& rpSet,
2816 const String* pPath,
2817 sal_Int16 nDialog,
2818 const String& rStandardDir,
2819 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
2821 ErrCode nRet;
2822 FileDialogHelper aDialog( nFlags, rFact, nDialog, 0, 0, rStandardDir, rBlackList );
2824 String aPath;
2825 if ( pPath )
2826 aPath = *pPath;
2828 nRet = aDialog.Execute( rpURLList, rpSet, rFilter, aPath );
2829 DBG_ASSERT( rFilter.SearchAscii(": ") == STRING_NOTFOUND, "Old filter name used!");
2831 return nRet;
2835 // ------------------------------------------------------------------------
2836 String EncodeSpaces_Impl( const String& rSource )
2838 String sRet( rSource );
2839 sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( " " ), DEFINE_CONST_UNICODE( "%20" ) );
2840 return sRet;
2843 // ------------------------------------------------------------------------
2844 String DecodeSpaces_Impl( const String& rSource )
2846 String sRet( rSource );
2847 sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( "%20" ), DEFINE_CONST_UNICODE( " " ) );
2848 return sRet;
2851 // ------------------------------------------------------------------------
2853 } // end of namespace sfx2