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