update dev300-m58
[ooovba.git] / fpicker / source / office / iodlg.cxx
blob00e714106e5006d825255e286a15248d8cc26cba
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iodlg.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
34 // includes --------------------------------------------------------------
36 #include "iodlg.hxx"
37 #include <tools/stream.hxx>
38 #include <tools/urlobj.hxx>
39 #include <vcl/fixed.hxx>
40 #include <vcl/lstbox.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/timer.hxx>
44 #include <unotools/ucbhelper.hxx>
45 #include <ucbhelper/contentbroker.hxx>
46 #include "svtools/ehdl.hxx"
47 #include "svtools/urihelper.hxx"
48 #include "svtools/pathoptions.hxx"
49 #include "svtools/viewoptions.hxx"
50 #include "svtools/fileview.hxx"
51 #include "svtools/inetoptions.hxx"
52 #include "svtools/sfxecode.hxx"
53 #include "svtools/svarray.hxx"
54 #include "svtools/svtabbx.hxx"
56 #define _SVSTDARR_USHORTS
57 #define _SVSTDARR_STRINGSDTOR
58 #include "svtools/svstdarr.hxx"
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <unotools/localfilehelper.hxx>
62 #ifndef _SVTOOLS_HRC
63 #include "svtools/svtools.hrc"
64 #endif
65 #ifndef _SVT_HELPID_HRC
66 #include "svtools/helpid.hrc"
67 #endif
68 #ifndef _SVTOOLS_IODLGIMPL_HRC
69 #include "iodlg.hrc"
70 #endif
71 #include "rtl/instance.hxx"
72 #include "asyncfilepicker.hxx"
73 #include "iodlgimp.hxx"
74 #include "svtools/inettbc.hxx"
75 #include "svtools/syslocale.hxx"
76 #include "svtools/QueryFolderName.hxx"
77 #ifndef _RTL_USTRING_HXX
78 #include <rtl/ustring.hxx>
79 #endif
80 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
81 #include <com/sun/star/ucb/XContentProviderManager.hpp>
82 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
83 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
84 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
85 #include <com/sun/star/beans/PropertyValue.hpp>
86 #include <com/sun/star/sdbc/XResultSet.hpp>
87 #include <com/sun/star/sdbc/XRow.hpp>
88 #include <com/sun/star/util/URL.hpp>
89 #include <com/sun/star/uno/Exception.hpp>
90 #include <com/sun/star/uno/Reference.hxx>
91 #include <com/sun/star/util/XURLTransformer.hpp>
92 #include <com/sun/star/uno/RuntimeException.hpp>
93 #include <com/sun/star/beans/XPropertySet.hpp>
95 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
96 #include <comphelper/processfactory.hxx>
97 #endif
98 #include <osl/file.h>
99 #include <vcl/waitobj.hxx>
101 // #97148# ------------------------------------
102 #include <com/sun/star/task/XInteractionHandler.hpp>
103 #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
104 #include "fpinteraction.hxx"
105 #include <osl/process.h>
106 #include <comphelper/interaction.hxx>
108 #include <algorithm>
109 #include <functional>
111 //#define AUTOSELECT_USERFILTER
112 // define this for the experimental feature of user-filter auto selection
113 // means if the user enters e.g. *.doc<enter>, and there is a filter which is responsible for *.doc files (only),
114 // then this filter is selected automatically
116 using namespace ::com::sun::star::beans;
117 using namespace ::com::sun::star::frame;
118 using namespace ::com::sun::star::ui::dialogs;
119 using namespace ::com::sun::star::uno;
120 using namespace ::com::sun::star::lang;
121 using namespace ::com::sun::star::ucb;
122 using namespace ::com::sun::star::container;
123 using namespace ::com::sun::star::task;
124 using namespace ::com::sun::star::sdbc;
125 using namespace ::utl;
126 using namespace ::svt;
128 using namespace ExtendedFilePickerElementIds;
129 using namespace CommonFilePickerElementIds;
130 using namespace InternalFilePickerElementIds;
132 #define IODLG_CONFIGNAME String(RTL_CONSTASCII_USTRINGPARAM("FileDialog"))
133 #define IMPGRF_CONFIGNAME String(RTL_CONSTASCII_USTRINGPARAM("ImportGraphicDialog"))
135 #define GET_DECODED_NAME(aObj) \
136 aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET )
138 // Zeit die beim Traveln in der Filterbox gewartet wird,
139 // bis in der Browsebox gefiltert wird ( in ms ).
140 #define TRAVELFILTER_TIMEOUT 750
142 #define WIDTH_ADDITION 15
144 // functions -------------------------------------------------------------
146 namespace
149 //-----------------------------------------------------------------------------
150 String getMostCurrentFilter( SvtExpFileDlg_Impl* pImpl )
152 DBG_ASSERT( pImpl, "invalid impl pointer" );
153 const SvtFileDialogFilter_Impl* pFilter = pImpl->_pUserFilter;
155 if ( !pFilter )
156 pFilter = pImpl->GetCurFilter();
158 // Filtern.
159 if ( !pFilter )
160 return String();
162 return pFilter->GetType();
165 //-----------------------------------------------------------------------------
166 sal_Bool restoreCurrentFilter( SvtExpFileDlg_Impl* _pImpl )
168 DBG_ASSERT( _pImpl->GetCurFilter(), "restoreCurrentFilter: no current filter!" );
169 DBG_ASSERT( _pImpl->GetCurFilterDisplayName().Len(), "restoreCurrentFilter: no current filter (no display name)!" );
171 _pImpl->SelectFilterListEntry( _pImpl->GetCurFilterDisplayName() );
173 #ifdef DBG_UTIL
174 String sSelectedDisplayName;
175 DBG_ASSERT( ( _pImpl->GetSelectedFilterEntry( sSelectedDisplayName ) == _pImpl->GetCurFilter() )
176 && ( sSelectedDisplayName == _pImpl->GetCurFilterDisplayName() ),
177 "restoreCurrentFilter: inconsistence!" );
178 #endif
179 return _pImpl->m_bNeedDelayedFilterExecute;
182 //-----------------------------------------------------------------------------
183 String GetFsysExtension_Impl( const String& rFile, const String& rLastFilterExt )
185 xub_StrLen nDotPos = rFile.SearchBackward( '.' );
186 if ( nDotPos != STRING_NOTFOUND )
188 if ( rLastFilterExt.Len() )
190 if ( rFile.Copy( nDotPos + 1 ).EqualsIgnoreCaseAscii( rLastFilterExt ) )
191 return String( rLastFilterExt );
193 else
194 return String( rFile.Copy( nDotPos ) );
196 return String();
199 //-----------------------------------------------------------------------------
200 void SetFsysExtension_Impl( String& rFile, const String& rExtension )
202 const sal_Unicode* p0 = rFile.GetBuffer();
203 const sal_Unicode* p1 = p0 + rFile.Len() - 1;
204 while ( p1 >= p0 && *p1 != sal_Unicode( '.' ) )
205 p1--;
206 if ( p1 >= p0 )
207 // remove old extension
208 rFile.Erase(
209 sal::static_int_cast< xub_StrLen >(
210 p1 - p0 + 1 - ( rExtension.Len() > 0 ? 0 : 1 ) ) );
211 else if ( rExtension.Len() )
212 // no old extension
213 rFile += sal_Unicode( '.' );
214 rFile += rExtension;
217 //-----------------------------------------------------------------------------
218 // move the control with the given offset
219 void lcl_MoveControl( Control* _pControl, sal_Int32 _nDeltaX, sal_Int32 _nDeltaY, sal_Int32* _pMaxY = NULL )
221 if ( _pControl )
223 Point aNewPos = _pControl->GetPosPixel();
225 // adjust the vertical position
226 aNewPos.Y() += _nDeltaY;
227 if ( _pMaxY && ( aNewPos.Y() > *_pMaxY ) )
228 *_pMaxY = aNewPos.Y();
230 // adjust the horizontal position
231 aNewPos.X() += _nDeltaX;
233 _pControl->SetPosPixel( aNewPos );
237 //-------------------------------------------------------------------------
238 void lcl_autoUpdateFileExtension( SvtFileDialog* _pDialog, const String& _rLastFilterExt )
240 // if auto extension is enabled ....
241 if ( _pDialog->isAutoExtensionEnabled() )
243 // automatically switch to the extension of the (maybe just newly selected) extension
244 String aNewFile = _pDialog->getCurrentFileText( );
245 String aExt = GetFsysExtension_Impl( aNewFile, _rLastFilterExt );
247 // but only if there already is an extension
248 if ( aExt.Len() )
250 // check if it is a real file extension, and not only the "post-dot" part in
251 // a directory name
252 // 28.03.2002 - 98337 - fs@openoffice.org
253 sal_Bool bRealExtensions = sal_True;
254 if ( STRING_NOTFOUND != aExt.Search( '/' ) )
255 bRealExtensions = sal_False;
256 else if ( STRING_NOTFOUND != aExt.Search( '\\' ) )
257 bRealExtensions = sal_False;
258 else
260 // no easy way to tell, because the part containing the dot already is the last
261 // segment of the complete file name
262 // So we have to check if the file name denotes a folder or a file.
263 // For performance reasons, we do this for file urls only
264 INetURLObject aURL( aNewFile );
265 if ( INET_PROT_NOT_VALID == aURL.GetProtocol() )
267 String sURL;
268 if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aNewFile, sURL ) )
269 aURL = INetURLObject( sURL );
271 if ( INET_PROT_FILE == aURL.GetProtocol() )
273 // #97148# & #102204# -----
276 bRealExtensions = !_pDialog->ContentIsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
278 catch( ::com::sun::star::uno::Exception& )
280 DBG_WARNING( "Exception in lcl_autoUpdateFileExtension" );
285 if ( bRealExtensions )
287 SetFsysExtension_Impl( aNewFile, _pDialog->GetDefaultExt() );
288 _pDialog->setCurrentFileText( aNewFile );
294 //-------------------------------------------------------------------------
295 sal_Bool lcl_getHomeDirectory( const String& _rForURL, String& /* [out] */ _rHomeDir )
297 _rHomeDir.Erase();
299 // now ask the content broker for a provider for this scheme
300 //=================================================================
303 // get the content provider manager
304 ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
305 Reference< XContentProviderManager > xProviderManager;
306 if ( pBroker )
307 xProviderManager = pBroker->getContentProviderManagerInterface();
309 //=================================================================
310 // get the provider for the current scheme
311 Reference< XContentProvider > xProvider;
312 if ( xProviderManager.is() )
313 xProvider = xProviderManager->queryContentProvider( _rForURL );
315 DBG_ASSERT( xProvider.is(), "lcl_getHomeDirectory: could not find a (valid) content provider for the current URL!" );
316 Reference< XPropertySet > xProviderProps( xProvider, UNO_QUERY );
317 if ( xProviderProps.is() )
319 Reference< XPropertySetInfo > xPropInfo = xProviderProps->getPropertySetInfo();
320 const ::rtl::OUString sHomeDirPropertyName( RTL_CONSTASCII_USTRINGPARAM( "HomeDirectory" ) );
321 if ( !xPropInfo.is() || xPropInfo->hasPropertyByName( sHomeDirPropertyName ) )
323 ::rtl::OUString sHomeDirectory;
324 xProviderProps->getPropertyValue( sHomeDirPropertyName ) >>= sHomeDirectory;
325 _rHomeDir = sHomeDirectory;
329 catch( const Exception& )
331 DBG_ERROR( "lcl_getHomeDirectory: caught an exception!" );
333 return 0 < _rHomeDir.Len();
336 //---------------------------------------------------------------------
337 static String lcl_ensureFinalSlash( const String& _rDir )
339 INetURLObject aWorkPathObj( _rDir, INET_PROT_FILE );
340 aWorkPathObj.setFinalSlash();
341 return aWorkPathObj.GetMainURL( INetURLObject::NO_DECODE );
344 //---------------------------------------------------------------------
345 void convertStringListToUrls( const String& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash )
347 const sal_Unicode s_cSeparator =
348 #if defined(WNT) || defined(OS2)
350 #else
352 #endif
354 xub_StrLen nTokens = _rColonSeparatedList.GetTokenCount( s_cSeparator );
355 _rTokens.resize( 0 ); _rTokens.reserve( nTokens );
356 for ( xub_StrLen i=0; i<nTokens; ++i )
358 // the current token in the list
359 String sCurrentToken = _rColonSeparatedList.GetToken( i, s_cSeparator );
360 if ( !sCurrentToken.Len() )
361 continue;
363 INetURLObject aCurrentURL;
365 String sURL;
366 if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) )
367 aCurrentURL = INetURLObject( sURL );
368 else
370 // smart URL parsing, assuming FILE protocol
371 aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE );
374 if ( _bFinalSlash )
375 aCurrentURL.setFinalSlash( );
376 else
377 aCurrentURL.removeFinalSlash( );
378 _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) );
382 //---------------------------------------------------------------------
383 struct RemoveFinalSlash : public ::std::unary_function< String, void >
385 void operator()( String& _rURL )
387 INetURLObject aURL( _rURL );
388 #if defined(WNT) || defined(OS2)
389 if ( aURL.getSegmentCount() > 1 )
390 #endif
391 aURL.removeFinalSlash( );
392 _rURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
396 // -----------------------------------------------------------------------
397 /** retrieves the value of an environment variable
398 @return <TRUE/> if and only if the retrieved string value is not empty
400 bool getEnvironmentValue( const sal_Char* _pAsciiEnvName, ::rtl::OUString& _rValue )
402 _rValue = ::rtl::OUString();
403 ::rtl::OUString sEnvName = ::rtl::OUString::createFromAscii( _pAsciiEnvName );
404 osl_getEnvironment( sEnvName.pData, &_rValue.pData );
405 return _rValue.getLength() != 0;
409 //***************************************************************************
410 // ControlChain_Impl
411 //***************************************************************************
413 struct ControlChain_Impl
415 Window* _pControl;
416 ControlChain_Impl* _pNext;
417 BOOL _bHasOwnerShip;
419 ControlChain_Impl( Window* pControl, ControlChain_Impl* pNext );
420 ~ControlChain_Impl();
423 //***************************************************************************
425 ControlChain_Impl::ControlChain_Impl
427 Window* pControl,
428 ControlChain_Impl* pNext
430 : _pControl( pControl ),
431 _pNext( pNext ),
432 _bHasOwnerShip( TRUE )
436 //***************************************************************************
438 ControlChain_Impl::~ControlChain_Impl()
440 if ( _bHasOwnerShip )
442 delete _pControl;
444 delete _pNext;
447 //*****************************************************************************
448 // ResMgrHolder
449 //*****************************************************************************
450 namespace
452 struct ResMgrHolder
454 ResMgr * operator ()()
456 return ResMgr::CreateResMgr (CREATEVERSIONRESMGR_NAME(fps_office));
459 static ResMgr * getOrCreate()
461 return rtl_Instance<
462 ResMgr, ResMgrHolder,
463 osl::MutexGuard, osl::GetGlobalMutex >::create (
464 ResMgrHolder(), osl::GetGlobalMutex());
468 struct SvtResId : public ResId
470 SvtResId (USHORT nId) : ResId (nId, *ResMgrHolder::getOrCreate()) {}
474 //*****************************************************************************
475 // SvtFileDialog
476 //*****************************************************************************
477 SvtFileDialog::SvtFileDialog
479 Window* _pParent,
480 WinBits nBits,
481 WinBits nExtraBits
483 ModalDialog( _pParent, SvtResId( DLG_SVT_EXPLORERFILE ) )
485 ,_pUserControls( NULL )
486 ,_pCbReadOnly( NULL )
487 ,_pCbLinkBox( NULL)
488 ,_pCbPreviewBox( NULL )
489 ,_pCbSelection( NULL )
490 ,_pPbPlay( NULL )
491 ,_pPrevWin( NULL )
492 ,_pPrevBmp( NULL )
493 ,_pFileView( NULL )
494 ,_pFileNotifier( NULL )
495 ,_pImp( new SvtExpFileDlg_Impl( nBits ) )
496 ,_nExtraBits( nExtraBits )
497 ,_bIsInExecute( FALSE )
498 ,m_bInExecuteAsync( false )
499 ,m_bHasFilename( false )
501 Init_Impl( nBits );
504 //*****************************************************************************
506 SvtFileDialog::SvtFileDialog ( Window* _pParent, WinBits nBits )
507 :ModalDialog( _pParent, SvtResId( DLG_SVT_EXPLORERFILE ) )
508 ,_pUserControls( NULL )
509 ,_pCbReadOnly( NULL )
510 ,_pCbLinkBox( NULL)
511 ,_pCbPreviewBox( NULL )
512 ,_pCbSelection( NULL )
513 ,_pPbPlay( NULL )
514 ,_pPrevWin( NULL )
515 ,_pPrevBmp( NULL )
516 ,_pFileView( NULL )
517 ,_pFileNotifier( NULL )
518 ,_pImp( new SvtExpFileDlg_Impl( nBits ) )
519 ,_nExtraBits( 0L )
520 ,_bIsInExecute( FALSE )
521 ,m_bHasFilename( false )
523 Init_Impl( nBits );
526 //*****************************************************************************
528 SvtFileDialog::~SvtFileDialog()
530 if ( _pImp->_aIniKey.Len() )
532 // save window state
533 SvtViewOptions aDlgOpt( E_DIALOG, _pImp->_aIniKey );
534 aDlgOpt.SetWindowState( String( GetWindowState(), osl_getThreadTextEncoding() ) );
535 String sUserData = _pFileView->GetConfigString();
536 aDlgOpt.SetUserItem( ::rtl::OUString::createFromAscii( "UserData" ),
537 makeAny( ::rtl::OUString( sUserData ) ) );
540 _pFileView->SetSelectHdl( Link() );
542 delete _pImp;
543 delete _pFileView;
545 delete _pCbReadOnly;
546 delete _pCbLinkBox;
547 delete _pCbPreviewBox;
548 delete _pCbSelection;
549 delete _pPbPlay;
550 delete _pPrevWin;
551 delete _pPrevBmp;
553 delete _pUserControls;
556 //*****************************************************************************
558 void SvtFileDialog::Init_Impl
560 WinBits nStyle
563 sal_Bool bIsHighContrast = GetDisplayBackground().GetColor().IsDark();
564 m_aImages = ImageList( SvtResId( bIsHighContrast ? RID_FILEPICKER_IMAGES_HC : RID_FILEPICKER_IMAGES ) );
566 _pImp->_nStyle = nStyle;
567 _pImp->_a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
568 _pImp->_eMode = ( nStyle & WB_SAVEAS ) ? FILEDLG_MODE_SAVE : FILEDLG_MODE_OPEN;
569 _pImp->_eDlgType = FILEDLG_TYPE_FILEDLG;
571 if ( ( nStyle & SFXWB_PATHDIALOG ) == SFXWB_PATHDIALOG )
572 _pImp->_eDlgType = FILEDLG_TYPE_PATHDLG;
574 // Set the directory for the "back to the default dir" button
575 INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
576 SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
578 // Reichweite bestimmen.
579 if ( !( nStyle & SFXWB_NOREMOTE ) )
581 _pImp->_nState |= FILEDLG_STATE_REMOTE;
584 // Kontrollelement erzeugen, wobei die Reihenfolge die Tab-Steuerung
585 // bestimmt.
586 _pImp->_pFtFileName = new FixedText( this, SvtResId( FT_EXPLORERFILE_FILENAME ) );
588 SvtURLBox* pURLBox = new SvtURLBox( this );
589 pURLBox->SetUrlFilter( &m_aURLFilter );
590 _pImp->_pEdFileName = pURLBox;
592 Edit aDummy( this, SvtResId( ED_EXPLORERFILE_FILENAME ) );
593 _pImp->_pEdFileName->SetPosSizePixel( aDummy.GetPosPixel(), aDummy.GetSizePixel() );
594 _pImp->_pEdFileName->Show();
595 pURLBox->SetSelectHdl( LINK( this, SvtFileDialog, EntrySelectHdl_Impl ) );
596 pURLBox->SetOpenHdl( STATIC_LINK( this, SvtFileDialog, OpenHdl_Impl ) );
598 // in folder picker mode, only auto-complete directories (no files)
599 bool bIsFolderPicker = ( _pImp->_eDlgType == FILEDLG_TYPE_PATHDLG );
600 pURLBox->SetOnlyDirectories( bIsFolderPicker );
602 // in save mode, don't use the autocompletion as selection in the edit part
603 bool bSaveMode = ( FILEDLG_MODE_SAVE == _pImp->_eMode );
604 pURLBox->SetNoURLSelection( bSaveMode );
606 _pImp->_pEdFileName->SetHelpId( HID_FILEDLG_AUTOCOMPLETEBOX );
608 _pImp->_pFtFileType = new FixedText( this, SvtResId( FT_EXPLORERFILE_FILETYPE ) );
609 _pImp->CreateFilterListControl( this, SvtResId( LB_EXPLORERFILE_FILETYPE ) );
611 // move the filter listbox to the space occupied by the version listbox
612 // if that box isn't needed
613 if ( !( _nExtraBits & SFX_EXTRA_SHOWVERSIONS ) &&
614 !( _nExtraBits & SFX_EXTRA_TEMPLATES ) &&
615 !( _nExtraBits & SFX_EXTRA_IMAGE_TEMPLATE ) )
618 FixedText aSharedListBoxLabel( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
619 _pImp->_pFtFileType->SetPosPixel( aSharedListBoxLabel.GetPosPixel() );
623 ListBox aSharedListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
624 _pImp->GetFilterListControl()->SetPosPixel( aSharedListBox.GetPosPixel() );
628 _pImp->_pFtCurrentPath = new FixedText( this, SvtResId( FT_EXPLORERFILE_CURRENTPATH ) );
629 WinBits nTmpStyle = _pImp->_pFtCurrentPath->GetStyle();
630 nTmpStyle |= WB_PATHELLIPSIS;
631 _pImp->_pFtCurrentPath->SetStyle( nTmpStyle );
633 _pImp->_pBtnFileOpen = new PushButton( this, SvtResId( BTN_EXPLORERFILE_OPEN ) );
634 _pImp->_pBtnCancel = new CancelButton( this, SvtResId( BTN_EXPLORERFILE_CANCEL ) );
635 _pImp->_pBtnHelp = new HelpButton( this, SvtResId( BTN_EXPLORERFILE_HELP ) );
637 _pImp->_pBtnUp = new SvtUpButton_Impl( this, SvtResId( BTN_EXPLORERFILE_UP ) );
638 _pImp->_pBtnNewFolder = new ImageButton( this, SvtResId( BTN_EXPLORERFILE_NEWFOLDER ) );
639 _pImp->_pBtnNewFolder->SetStyle( _pImp->_pBtnNewFolder->GetStyle() | WB_NOPOINTERFOCUS );
640 _pImp->_pBtnStandard = new SvtTravelButton_Impl( this, SvtResId( BTN_EXPLORERFILE_STANDARD ) );
642 _pImp->_pBtnUp->SetAccessibleName( _pImp->_pBtnUp->GetQuickHelpText() );
643 _pImp->_pBtnNewFolder->SetAccessibleName( _pImp->_pBtnNewFolder->GetQuickHelpText() );
644 _pImp->_pBtnStandard->SetAccessibleName( _pImp->_pBtnStandard->GetQuickHelpText() );
646 if ( ( nStyle & SFXWB_MULTISELECTION ) == SFXWB_MULTISELECTION )
647 _pImp->_bMultiSelection = TRUE;
649 _pFileView = new SvtFileView( this, SvtResId( CTL_EXPLORERFILE_FILELIST ),
650 FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType,
651 _pImp->_bMultiSelection );
652 _pFileView->SetUrlFilter( &m_aURLFilter );
653 _pFileView->EnableAutoResize();
655 _pFileView->SetHelpId( HID_FILEDLG_STANDARD );
656 _pFileView->SetStyle( _pFileView->GetStyle() | WB_TABSTOP );
658 // Positionen und Groessen der Knoepfe bestimmen.
659 Image aNewFolderImg( GetButtonImage( IMG_FILEDLG_CREATEFOLDER ) );
660 _pImp->_pBtnNewFolder->SetModeImage( aNewFolderImg );
662 Size aSize( aNewFolderImg.GetSizePixel() );
663 aSize.Width() += FILEDIALOG_DEF_IMAGEBORDER;
664 aSize.Height() += FILEDIALOG_DEF_IMAGEBORDER;
665 _pImp->_pBtnNewFolder->SetSizePixel( aSize );
666 _pImp->_pBtnUp->SetSizePixel( aSize );
667 _pImp->_pBtnStandard->SetSizePixel( aSize );
669 Size aDlgSize = GetOutputSizePixel();
670 long n6AppFontInPixel =
671 LogicToPixel( Size( 6, 0 ), MAP_APPFONT ).Width();
672 long n3AppFontInPixel =
673 LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
675 // calculate the length of all buttons
676 const USHORT nBtnCount = 3; // "previous level", "new folder" and "standard dir"
677 long nDelta = n6AppFontInPixel; // right border
678 nDelta += ( nBtnCount * aSize.Width() ); // button count * button width
679 nDelta += ( n3AppFontInPixel + n3AppFontInPixel / 2 ); // spacing 1*big 1*small
681 Point aPos(
682 aDlgSize.Width() - nDelta,
683 _pImp->_pBtnUp->GetPosPixel().Y()
685 Size aCurPathSize(
686 aPos.X() - n6AppFontInPixel,
687 _pImp->_pFtCurrentPath->GetOutputSizePixel().Height()
689 _pImp->_pFtCurrentPath->SetOutputSizePixel( aCurPathSize );
690 _pImp->_pBtnUp->SetPosPixel( aPos );
691 aPos.X() += aSize.Width();
692 aPos.X() += n3AppFontInPixel;
693 _pImp->_pBtnNewFolder->SetPosPixel( aPos );
694 aPos.X() += aSize.Width();
695 aPos.X() += n3AppFontInPixel / 2;
696 _pImp->_pBtnStandard->SetPosPixel( aPos );
697 nDelta = aSize.Height();
698 nDelta -= aCurPathSize.Height();
699 nDelta /= 2;
700 Point aCurPathPos = _pImp->_pFtCurrentPath->GetPosPixel();
701 aCurPathPos.Y() += nDelta;
702 _pImp->_pFtCurrentPath->SetPosPixel( aCurPathPos );
704 if ( nStyle & SFXWB_READONLY )
706 _pCbReadOnly = new CheckBox( this, SvtResId( CB_EXPLORERFILE_READONLY ) );
707 _pCbReadOnly->SetHelpId( HID_FILEOPEN_READONLY );
708 _pCbReadOnly->SetText( SvtResId( STR_SVT_FILEPICKER_READONLY ) );
709 AddControl( _pCbReadOnly );
710 ReleaseOwnerShip( _pCbReadOnly );
711 _pCbReadOnly->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
714 if ( nStyle & SFXWB_PASSWORD )
716 _pImp->_pCbPassword = new CheckBox( this, SvtResId( CB_EXPLORERFILE_PASSWORD ) );
717 _pImp->_pCbPassword->SetText( SvtResId( STR_SVT_FILEPICKER_PASSWORD ) );
718 AddControl( _pImp->_pCbPassword );
719 ReleaseOwnerShip( _pImp->_pCbPassword );
720 _pImp->_pCbPassword->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
723 // set the ini file for extracting the size
724 _pImp->_aIniKey = IODLG_CONFIGNAME;
726 AddControls_Impl( );
728 // Zahl der Pixel bestimmen, um die die anderen Elemente in der Position
729 // Angepasst werden muessen.
730 aPos.Y() += aSize.Height();
731 aPos.Y() += LogicToPixel( Size( 0, 6 ), MAP_APPFONT ).Height();
732 long nYOffset = aPos.Y();
733 aPos = _pFileView->GetPosPixel();
734 nYOffset -= aPos.Y();
736 // Positionen der uebrigen Elemente anpassen.
737 aPos.Y() += nYOffset;
738 _pFileView->SetPosPixel( aPos );
740 lcl_MoveControl( _pImp->_pFtFileName, 0, nYOffset );
741 lcl_MoveControl( _pImp->_pEdFileName, 0, nYOffset );
743 lcl_MoveControl( _pImp->_pFtFileVersion, 0, nYOffset );
744 lcl_MoveControl( _pImp->_pLbFileVersion, 0, nYOffset );
746 lcl_MoveControl( _pImp->_pFtTemplates, 0, nYOffset );
747 lcl_MoveControl( _pImp->_pLbTemplates, 0, nYOffset );
749 lcl_MoveControl( _pImp->_pFtImageTemplates, 0, nYOffset );
750 lcl_MoveControl( _pImp->_pLbImageTemplates, 0, nYOffset );
752 lcl_MoveControl( _pImp->_pFtFileType, 0, nYOffset );
753 lcl_MoveControl( _pImp->GetFilterListControl(), 0, nYOffset );
755 lcl_MoveControl( _pImp->_pBtnFileOpen, 0, nYOffset );
756 lcl_MoveControl( _pImp->_pBtnCancel, 0, nYOffset );
758 lcl_MoveControl( _pImp->_pBtnHelp, 0, nYOffset + 3 );
759 // a little more spacing between Cancel- and HelpButton
761 // Groesse des Dialoges anpassen.
762 aSize = GetSizePixel();
763 aSize.Height() += nYOffset;
764 SetSizePixel( aSize );
766 // Beschriftungen dem Modus anpassen.
767 USHORT nResId = STR_EXPLORERFILE_OPEN;
768 USHORT nButtonResId = 0;
770 if ( nStyle & WB_SAVEAS )
772 nResId = STR_EXPLORERFILE_SAVE;
773 nButtonResId = STR_EXPLORERFILE_BUTTONSAVE;
776 if ( ( nStyle & SFXWB_PATHDIALOG ) == SFXWB_PATHDIALOG )
778 _pImp->_pFtFileName->SetText( SvtResId( STR_PATHNAME ) );
779 nResId = STR_PATHSELECT;
780 nButtonResId = STR_BUTTONSELECT;
783 SetText( SvtResId( nResId ) );
785 if ( nButtonResId )
786 _pImp->_pBtnFileOpen->SetText( SvtResId( nButtonResId ) );
788 if ( FILEDLG_TYPE_FILEDLG != _pImp->_eDlgType )
790 _pImp->_pFtFileType->Hide();
791 _pImp->GetFilterListControl()->Hide();
794 // Einstellungen der Steuerelemente vornehmen.
795 _pImp->_pBtnNewFolder->SetClickHdl( STATIC_LINK( this, SvtFileDialog, NewFolderHdl_Impl ) );
796 _pImp->_pBtnFileOpen->SetClickHdl( STATIC_LINK( this, SvtFileDialog, OpenHdl_Impl ) );
797 _pImp->_pBtnCancel->SetClickHdl( LINK( this, SvtFileDialog, CancelHdl_Impl ) );
798 _pImp->SetFilterListSelectHdl( STATIC_LINK( this, SvtFileDialog, FilterSelectHdl_Impl ) );
799 _pImp->_pEdFileName->SetGetFocusHdl( STATIC_LINK( this, SvtFileDialog, FileNameGetFocusHdl_Impl ) );
800 _pImp->_pEdFileName->SetModifyHdl( STATIC_LINK( this, SvtFileDialog, FileNameModifiedHdl_Impl ) );
801 _pFileView->SetSelectHdl( LINK( this, SvtFileDialog, SelectHdl_Impl ) );
802 _pFileView->SetDoubleClickHdl( LINK( this, SvtFileDialog, DblClickHdl_Impl ) );
803 _pFileView->SetOpenDoneHdl( LINK( this, SvtFileDialog, OpenDoneHdl_Impl ) );
805 // Resourcen freigeben.
806 FreeResource();
808 // Timer fuer Filterbox Travel setzen
809 _pImp->_aFilterTimer.SetTimeout( TRAVELFILTER_TIMEOUT );
810 _pImp->_aFilterTimer.SetTimeoutHdl( STATIC_LINK( this, SvtFileDialog, FilterSelectHdl_Impl ) );
812 if ( WB_SAVEAS & nStyle )
814 // different help ids if in save-as mode
815 // 90744 - 09.08.2001 - frank.schoenheit@sun.com
816 SetHelpId( HID_FILESAVE_DIALOG );
818 _pImp->_pEdFileName->SetHelpId( HID_FILESAVE_FILEURL );
819 _pImp->_pBtnFileOpen->SetHelpId( HID_FILESAVE_DOSAVE );
820 _pImp->_pBtnNewFolder->SetHelpId( HID_FILESAVE_CREATEDIRECTORY );
821 _pImp->_pBtnStandard->SetHelpId( HID_FILESAVE_DEFAULTDIRECTORY );
822 _pImp->_pBtnUp->SetHelpId( HID_FILESAVE_LEVELUP );
823 _pImp->GetFilterListControl()->SetHelpId( HID_FILESAVE_FILETYPE );
824 _pFileView->SetHelpId( HID_FILESAVE_FILEVIEW );
826 // formerly, there was only _pLbFileVersion, which was used for 3 different
827 // use cases. For reasons of maintainability, I introduced extra members (_pLbTemplates, _pLbImageTemplates)
828 // for the extra use cases, and separated _pLbFileVersion
829 // I did not find out in which cases the help ID is really needed HID_FILESAVE_TEMPLATE - all
830 // tests I made lead to a dialog where _no_ of the three list boxes was present.
831 // 96930 - 15.08.2002 - fs@openoffice.org
832 if ( _pImp->_pLbFileVersion )
833 _pImp->_pLbFileVersion->SetHelpId( HID_FILESAVE_TEMPLATE );
834 if ( _pImp->_pLbTemplates )
835 _pImp->_pLbTemplates->SetHelpId( HID_FILESAVE_TEMPLATE );
836 if ( _pImp->_pLbImageTemplates )
837 _pImp->_pLbImageTemplates->SetHelpId( HID_FILESAVE_TEMPLATE );
839 if ( _pImp->_pCbPassword ) _pImp->_pCbPassword->SetHelpId( HID_FILESAVE_SAVEWITHPASSWORD );
840 if ( _pImp->_pCbAutoExtension ) _pImp->_pCbAutoExtension->SetHelpId( HID_FILESAVE_AUTOEXTENSION );
841 if ( _pImp->_pCbOptions ) _pImp->_pCbOptions->SetHelpId( HID_FILESAVE_CUSTOMIZEFILTER );
842 if ( _pCbSelection ) _pCbSelection->SetHelpId( HID_FILESAVE_SELECTION );
845 // correct the z-order of the controls
846 implArrangeControls();
848 // special URLs, such as favourites and "restricted" paths
849 implInitializeSpecialURLLists( );
851 /// read our settings from the configuration
852 m_aConfiguration = OConfigurationTreeRoot::createWithServiceFactory(
853 ::comphelper::getProcessServiceFactory(),
854 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI/FilePicker" ) )
858 //*****************************************************************************
860 IMPL_STATIC_LINK( SvtFileDialog, NewFolderHdl_Impl, PushButton*, EMPTYARG )
862 pThis->_pFileView->EndInplaceEditing( false );
864 INetURLObject aObj( pThis->_pFileView->GetViewURL() );
865 String sFolderName = aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 );
866 svtools::QueryFolderNameDialog aDlg( pThis, sFolderName, String( SvtResId( STR_SVT_NEW_FOLDER ) ) );
867 sal_Bool bHandled = sal_False;
869 while ( !bHandled )
871 if ( aDlg.Execute() == RET_OK )
872 bHandled = pThis->_pFileView->CreateNewFolder( aDlg.GetName() );
873 else
874 bHandled = sal_True;
877 return 0;
880 //*****************************************************************************
882 IMPL_STATIC_LINK_NOINSTANCE( SvtFileDialog, ViewHdl_Impl, ImageButton*, EMPTYARG )
884 return 0;
887 //*****************************************************************************
888 //-----------------------------------------------------------------------------
889 sal_Bool SvtFileDialog::createNewUserFilter( const String& _rNewFilter, sal_Bool _bAllowUserDefExt )
891 // delete the old user filter and create a new one
892 DELETEZ( _pImp->_pUserFilter );
893 _pImp->_pUserFilter = new SvtFileDialogFilter_Impl( _rNewFilter, _rNewFilter );
895 // remember the extension
896 sal_Bool bIsAllFiles = _rNewFilter.EqualsAscii( FILEDIALOG_FILTER_ALL );
897 if ( bIsAllFiles )
898 EraseDefaultExt();
899 else
900 SetDefaultExt( _rNewFilter.Copy( 2 ) );
901 // TODO: this is nonsense. In the whole file there are a lotta places where we assume that a user filter
902 // is always "*.<something>". But changing this would take some more time than I have now ...
903 // 05.12.2001 - 95486 - fs@openoffice.org
905 // now, the default extension is set to the one of the user filter (or empty)
906 // if the former is not allowed (_bAllowUserDefExt = <FALSE/>), we have to use the ext of the current filter
907 // (if possible)
908 sal_Bool bUseCurFilterExt = sal_True;
909 String sUserFilter = _pImp->_pUserFilter->GetType();
910 xub_StrLen nSepPos = sUserFilter.SearchBackward( '.' );
911 if ( STRING_NOTFOUND != nSepPos )
913 String sUserExt = sUserFilter.Copy( nSepPos + 1 );
914 if ( ( STRING_NOTFOUND == sUserExt.Search( '*' ) )
915 && ( STRING_NOTFOUND == sUserExt.Search( '?' ) )
917 bUseCurFilterExt = sal_False;
920 if ( !_bAllowUserDefExt || bUseCurFilterExt )
922 if ( _pImp->GetCurFilter( ) )
923 SetDefaultExt( _pImp->GetCurFilter( )->GetExtension() );
924 else
925 EraseDefaultExt();
928 // outta here
929 return bIsAllFiles;
932 //-----------------------------------------------------------------------------
933 #define FLT_NONEMPTY 0x0001
934 #define FLT_CHANGED 0x0002
935 #define FLT_USERFILTER 0x0004
936 #define FLT_ALLFILESFILTER 0x0008
938 //-----------------------------------------------------------------------------
939 sal_uInt16 SvtFileDialog::adjustFilter( const String& _rFilter )
941 sal_uInt16 nReturn = 0;
943 const sal_Bool bNonEmpty = ( _rFilter.Len() != 0 );
944 if ( bNonEmpty )
946 nReturn |= FLT_NONEMPTY;
948 sal_Bool bFilterChanged = sal_True;
950 // search for a corresponding filter
951 SvtFileDialogFilter_Impl* pFilter = FindFilter_Impl( _rFilter, FALSE, bFilterChanged );
953 #ifdef AUTOSELECT_USERFILTER
954 // if we found a filter which without allowing multi-extensions -> select it
955 if ( pFilter )
957 _pImp->SelectFilterListEntry( pFilter->GetName() );
958 _pImp->SetCurFilter( pFilter );
960 #endif // AUTOSELECT_USERFILTER
962 // look for multi-ext filters if necessary
963 if ( !pFilter )
964 pFilter = FindFilter_Impl( _rFilter, TRUE, bFilterChanged );
966 if ( bFilterChanged )
967 nReturn |= FLT_CHANGED;
969 if ( !pFilter )
971 nReturn |= FLT_USERFILTER;
972 // no filter found : use it as user defined filter
973 #ifdef AUTOSELECT_USERFILTER
974 if ( createNewUserFilter( _rFilter, sal_True ) )
975 #else
976 if ( createNewUserFilter( _rFilter, sal_False ) )
977 #endif
978 { // it's the "all files" filter
979 nReturn |= FLT_ALLFILESFILTER;
981 #ifdef AUTOSELECT_USERFILTER
982 // select the "all files" entry
983 String sAllFilesFilter( SvtResId( STR_FILTERNAME_ALL ) );
984 if ( _pImp->HasFilterListEntry( sAllFilesFilter ) )
986 _pImp->SelectFilterListEntry( sAllFilesFilter );
987 _pImp->SetCurFilter( _pImp->GetSelectedFilterEntry( sAllFilesFilter ) );
989 else
990 _pImp->SetNoFilterListSelection( ); // there is no "all files" entry
991 #endif // AUTOSELECT_USERFILTER
993 #ifdef AUTOSELECT_USERFILTER
994 else
995 _pImp->SetNoFilterListSelection( );
996 #endif // AUTOSELECT_USERFILTER
1000 return nReturn;
1003 //-----------------------------------------------------------------------------
1004 IMPL_LINK( SvtFileDialog, CancelHdl_Impl, void*, EMPTYARG )
1006 if ( m_pCurrentAsyncAction.is() )
1008 m_pCurrentAsyncAction->cancel();
1009 onAsyncOperationFinished();
1011 else
1013 EndDialog( FALSE );
1015 return 1L;
1018 //-----------------------------------------------------------------------------
1019 IMPL_STATIC_LINK( SvtFileDialog, OpenHdl_Impl, void*, pVoid )
1021 if ( pThis->_pImp->_bMultiSelection && pThis->_pFileView->GetSelectionCount() > 1 )
1023 // bei Multiselektion spezielles Open
1024 pThis->OpenMultiSelection_Impl();
1025 return 0;
1028 String aFileName;
1029 String aOldPath( pThis->_pFileView->GetViewURL() );
1030 if ( pThis->_pImp->_bDoubleClick || pThis->_pFileView->HasChildPathFocus() )
1031 // Selection done by doubleclicking in the view, get filename from the view
1032 aFileName = pThis->_pFileView->GetCurrentURL();
1034 if ( !aFileName.Len() )
1036 // if an entry is selected in the view ....
1037 if ( pThis->_pFileView->GetSelectionCount() )
1038 { // -> use this one. This will allow us to step down this folder
1039 // #i8928# - 2002-12-20 - fs@openoffice.org
1040 aFileName = pThis->_pFileView->GetCurrentURL();
1044 if ( !aFileName.Len() )
1046 if ( pThis->_pImp->_eMode == FILEDLG_MODE_OPEN && pThis->_pImp->_pEdFileName->IsTravelSelect() )
1047 // OpenHdl called from URLBox; travelling through the list of URLs should not cause an opening
1048 return 0; // MBA->PB: seems to be called never ?!
1050 // get the URL from from the edit field ( if not empty )
1051 if ( pThis->_pImp->_pEdFileName->GetText().Len() )
1053 String aText = pThis->_pImp->_pEdFileName->GetText();
1055 // did we reach the root?
1056 if ( !INetURLObject( aOldPath ).getSegmentCount() )
1058 if ( ( aText.Len() == 2 && aText.EqualsAscii( ".." ) ) ||
1059 ( aText.Len() == 3 && ( aText.EqualsAscii( "..\\" ) || aText.EqualsAscii( "../" ) ) ) )
1060 // don't go higher than the root
1061 return 0;
1064 #if defined( UNX ) || defined( FS_PRIV_DEBUG )
1065 if ( ( 1 == aText.Len() ) && ( '~' == aText.GetBuffer()[0] ) )
1067 // go to the home directory
1068 if ( lcl_getHomeDirectory( pThis->_pFileView->GetViewURL(), aFileName ) )
1069 // in case we got a home dir, reset the text of the edit
1070 pThis->_pImp->_pEdFileName->SetText( String() );
1072 if ( !aFileName.Len() )
1073 #endif
1075 // get url from autocomplete edit
1076 aFileName = pThis->_pImp->_pEdFileName->GetURL();
1079 else if ( pVoid == pThis->_pImp->_pBtnFileOpen )
1080 // OpenHdl was called for the "Open" Button; if edit field is empty, use selected element in the view
1081 aFileName = pThis->_pFileView->GetCurrentURL();
1084 // MBA->PB: ?!
1085 if ( !aFileName.Len() && pVoid == pThis->_pImp->_pEdFileName && pThis->_pImp->_pUserFilter )
1087 DELETEZ( pThis->_pImp->_pUserFilter );
1088 return 0;
1091 USHORT nLen = aFileName.Len();
1092 if ( !nLen )
1094 // if the dialog was opened to select a folder, the last selected folder should be selected
1095 if( pThis->_pImp->_eDlgType == FILEDLG_TYPE_PATHDLG )
1097 aFileName = pThis->_pImp->_pFtCurrentPath->GetText();
1098 nLen = aFileName.Len();
1100 else
1101 // no file selected !
1102 return 0;
1105 // mark input as selected
1106 pThis->_pImp->_pEdFileName->SetSelection( Selection( 0, nLen ) );
1108 // if a path with wildcards is given, divide the string into path and wildcards
1109 String aFilter;
1110 if ( !pThis->IsolateFilterFromPath_Impl( aFileName, aFilter ) )
1111 return 0;
1113 // if a filter was retrieved, there were wildcards !
1114 sal_uInt16 nNewFilterFlags = pThis->adjustFilter( aFilter );
1115 if ( nNewFilterFlags & FLT_CHANGED )
1117 // cut off all text before wildcard in edit and select wildcard
1118 pThis->_pImp->_pEdFileName->SetText( aFilter );
1119 pThis->_pImp->_pEdFileName->SetSelection( Selection( 0, aFilter.Len() ) );
1123 INetURLObject aFileObject( aFileName );
1124 if ( ( aFileObject.GetProtocol() == INET_PROT_NOT_VALID ) && aFileName.Len() )
1126 String sCompleted = SvtURLBox::ParseSmart( aFileName, pThis->_pFileView->GetViewURL(), SvtPathOptions().GetWorkPath() );
1127 if ( sCompleted.Len() )
1128 aFileName = sCompleted;
1132 // Pr"ufen, ob es sich um einen Ordner handelt.
1133 BOOL bIsFolder = FALSE;
1135 // first thing before doing anyhing with the content: Reset it. When the user presses "open" (or "save" or "export",
1136 // for that matter), s/he wants the complete handling, including all possible error messages, even if s/he
1137 // does the same thing for the same content twice, s/he wants both fails to be displayed.
1138 // Without the reset, it could be that the content cached all relevant information, and will not display any
1139 // error messages for the same content a second time ....
1140 pThis->m_aContent.bindTo( ::rtl::OUString( ) );
1142 // #97148# & #102204# ---------
1143 if ( aFileName.Len() )
1145 // Make sure we have own Interaction Handler in place. We do not need
1146 // to intercept interactions here, but to record the fact that there
1147 // was an interaction.
1148 SmartContent::InteractionHandlerType eInterActionHandlerType
1149 = pThis->m_aContent.queryCurrentInteractionHandler();
1150 if ( ( eInterActionHandlerType == SmartContent::IHT_NONE ) ||
1151 ( eInterActionHandlerType == SmartContent::IHT_DEFAULT ) )
1152 pThis->m_aContent.enableOwnInteractionHandler(
1153 OFilePickerInteractionHandler::E_NOINTERCEPTION );
1155 bIsFolder = pThis->m_aContent.isFolder( aFileName );
1157 // access denied to the given resource - and interaction was already
1158 // used => break following operations
1159 OFilePickerInteractionHandler* pHandler
1160 = pThis->m_aContent.getOwnInteractionHandler();
1162 OSL_ENSURE( pHandler, "Got no Interaction Handler!!!" );
1164 if ( pHandler->wasAccessDenied() )
1165 return 0;
1167 if ( pThis->m_aContent.isInvalid() &&
1168 ( pThis->_pImp->_eMode == FILEDLG_MODE_OPEN ) )
1170 if ( !pHandler->wasUsed() )
1171 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS );
1173 return 0;
1176 // restore previous Interaction Handler
1177 if ( eInterActionHandlerType == SmartContent::IHT_NONE )
1178 pThis->m_aContent.disableInteractionHandler();
1179 else if ( eInterActionHandlerType == SmartContent::IHT_DEFAULT )
1180 pThis->m_aContent.enableDefaultInteractionHandler();
1183 if ( !bIsFolder // no existent folder
1184 && pThis->_pImp->_pCbAutoExtension // auto extension is enabled in general
1185 && pThis->_pImp->_pCbAutoExtension->IsChecked() // auto extension is really to be used
1186 && pThis->GetDefaultExt().Len() // there is a default extension
1187 && pThis->GetDefaultExt() != '*' // the default extension is not "all"
1188 && !( FILEDLG_MODE_SAVE == pThis->_pImp->_eMode // we're saving a file
1189 && pThis->_pFileView->GetSelectionCount() // there is a selected file in the file view -> it will later on
1190 ) // (in SvtFileDialog::GetPathList) be taken as file to save to
1191 // (#114818# - 2004-03-17 - fs@openoffice.org)
1192 && FILEDLG_MODE_OPEN != pThis->_pImp->_eMode // pb: #i83408# don't append extension on open
1195 // check extension and append the default extension if necessary
1196 appendDefaultExtension(aFileName,
1197 pThis->GetDefaultExt(),
1198 pThis->_pImp->GetCurFilter()->GetType());
1201 BOOL bOpenFolder = ( FILEDLG_TYPE_PATHDLG == pThis->_pImp->_eDlgType ) &&
1202 !pThis->_pImp->_bDoubleClick && pVoid != pThis->_pImp->_pEdFileName;
1203 if ( bIsFolder )
1205 if ( bOpenFolder )
1207 pThis->_aPath = aFileName;
1209 else
1211 if ( aFileName != pThis->_pFileView->GetViewURL() )
1213 if ( !pThis->m_aURLFilter.isUrlAllowed( aFileName ) )
1215 pThis->simulateAccessDenied( aFileName );
1216 return 0;
1219 pThis->OpenURL_Impl( aFileName );
1221 else
1223 if ( nNewFilterFlags & FLT_CHANGED )
1224 pThis->ExecuteFilter();
1227 return 0;
1230 else if ( !( nNewFilterFlags & FLT_NONEMPTY ) )
1232 // Ggf. URL speichern.
1233 pThis->_aPath = aFileName;
1235 else
1237 // Ggf. neu filtern.
1238 if ( nNewFilterFlags & FLT_CHANGED )
1239 pThis->ExecuteFilter();
1240 return 0;
1243 INetURLObject aFileObj( aFileName );
1244 if ( aFileObj.HasError() )
1246 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
1247 return 0;
1250 // if restrictions for the allowed folders are in place, we need to do a check here
1251 if ( !pThis->m_aURLFilter.isUrlAllowed( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
1253 pThis->simulateAccessDenied( aFileName );
1254 return 0;
1257 switch ( pThis->_pImp->_eMode )
1259 case FILEDLG_MODE_SAVE:
1261 if ( ::utl::UCBContentHelper::Exists( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
1263 QueryBox aBox( pThis, WB_YES_NO, SvtResId( STR_SVT_ALREADYEXISTOVERWRITE ) );
1264 if ( aBox.Execute() != RET_YES )
1265 return 0;
1267 else
1269 String aCurPath;
1270 if ( ::utl::LocalFileHelper::ConvertURLToSystemPath( aFileName, aCurPath ) )
1272 // if content does not exist: at least its path must exist
1273 INetURLObject aPathObj = aFileObj;
1274 aPathObj.removeSegment();
1275 // #97148# & #102204# ------------
1276 BOOL bFolder = pThis->m_aContent.isFolder( aPathObj.GetMainURL( INetURLObject::NO_DECODE ) );
1277 if ( !bFolder )
1279 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH );
1280 return 0;
1285 break;
1287 case FILEDLG_MODE_OPEN:
1289 // do an existence check herein, again
1290 // 16.11.2001 - 93107 - frank.schoenheit@sun.com
1292 if ( INET_PROT_FILE == aFileObj.GetProtocol( ) )
1294 sal_Bool bExists = sal_False;
1295 // #102204# --------------
1296 bExists = pThis->m_aContent.is( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) );
1299 if ( !bExists )
1301 String sError( SvtResId( RID_FILEOPEN_NOTEXISTENTFILE ) );
1303 String sInvalidFile( aFileObj.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
1304 if ( INET_PROT_FILE == aFileObj.GetProtocol() )
1305 { // if it's a file URL, transform the URL into system notation
1306 ::rtl::OUString sURL( sInvalidFile );
1307 ::rtl::OUString sSystem;
1308 osl_getSystemPathFromFileURL( sURL.pData, &sSystem.pData );
1309 sInvalidFile = sSystem;
1311 sError.SearchAndReplaceAscii( "$name$", sInvalidFile );
1313 ErrorBox aError( pThis, WB_OK, sError );
1314 aError.Execute();
1315 return 0;
1319 break;
1321 default:
1322 DBG_ERROR("SvtFileDialog, OpenHdl_Impl: invalid mode!");
1325 // Interessenten benachrichtigen.
1326 long nRet;
1328 if ( pThis->_aOKHdl.IsSet() )
1329 nRet = pThis->_aOKHdl.Call( pThis );
1330 else
1331 nRet = pThis->OK();
1333 if ( nRet )
1335 pThis->EndDialog( TRUE );
1338 return nRet;
1341 //*****************************************************************************
1343 void SvtFileDialog::EnableAutocompletion( BOOL _bEnable )
1345 _pImp->_pEdFileName->EnableAutocompletion( _bEnable );
1348 //*****************************************************************************
1350 IMPL_STATIC_LINK( SvtFileDialog, FilterSelectHdl_Impl, ListBox*, pBox )
1352 DBG_ASSERT( pBox, "SvtFileDialog:keine Instanz" );
1354 // wurde der Handler vom Travel-Timer gefeuert?
1355 if ( pBox == (ListBox*)&pThis->_pImp->_aFilterTimer )
1357 // Anzeige erneut filtern.
1358 pThis->ExecuteFilter();
1359 return 0;
1362 String sSelectedFilterDisplayName;
1363 SvtFileDialogFilter_Impl* pSelectedFilter = pThis->_pImp->GetSelectedFilterEntry( sSelectedFilterDisplayName );
1364 if ( !pSelectedFilter )
1365 { // there is no current selection. This happens if for instance the user selects a group separator using
1366 // the keyboard, and then presses enter: When the selection happens, we immediately deselect the entry,
1367 // so in this situation there is no current selection.
1368 if ( restoreCurrentFilter( pThis->_pImp ) )
1369 pThis->ExecuteFilter();
1371 else
1373 if ( pSelectedFilter->isGroupSeparator() )
1374 { // group separators can't be selected
1375 // return to the previously selected entry
1376 if ( pThis->_pImp->IsFilterListTravelSelect() )
1378 pThis->_pImp->SetNoFilterListSelection( );
1380 // stop the timer for executing the filter
1381 if ( pThis->_pImp->_aFilterTimer.IsActive() )
1382 pThis->_pImp->m_bNeedDelayedFilterExecute = sal_True;
1383 pThis->_pImp->_aFilterTimer.Stop();
1385 else
1387 if ( restoreCurrentFilter( pThis->_pImp ) )
1388 pThis->ExecuteFilter();
1391 else if ( ( pSelectedFilter != pThis->_pImp->GetCurFilter() )
1392 || pThis->_pImp->_pUserFilter
1395 // Store the old filter for the auto extension handling
1396 String sLastFilterExt = pThis->_pImp->GetCurFilter()->GetExtension();
1397 DELETEZ( pThis->_pImp->_pUserFilter );
1399 // Ggf. Filter des Benutzers entfernen.
1400 pThis->_pImp->SetCurFilter( pSelectedFilter, sSelectedFilterDisplayName );
1402 // Ggf. Endung anzeigen.
1403 pThis->SetDefaultExt( pSelectedFilter->GetExtension() );
1404 USHORT nSepPos = pThis->GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP );
1406 if ( nSepPos != STRING_NOTFOUND )
1407 pThis->EraseDefaultExt( nSepPos );
1409 // update the extension of the current file if necessary
1410 lcl_autoUpdateFileExtension( pThis, sLastFilterExt );
1412 // wenn der Benutzer schnell durch die Filterbox
1413 // travelt, nicht sofort Filtern
1414 if ( pThis->_pImp->IsFilterListTravelSelect() )
1416 // FilterSelectHdl_Impl soll in
1417 // TRAVELFILTER_TIMEOUT ms neu gefeuert werden
1418 pThis->_pImp->_aFilterTimer.Start();
1420 else
1422 // evtl. vorher gestarteten Timer stoppen
1423 pThis->_pImp->_aFilterTimer.Stop();
1425 // Anzeige erneut filtern.
1426 pThis->ExecuteFilter();
1431 return 0;
1434 //*****************************************************************************
1436 IMPL_STATIC_LINK( SvtFileDialog, FileNameGetFocusHdl_Impl, void*, EMPTYARG )
1438 pThis->_pFileView->SetNoSelection();
1439 pThis->_pFileView->Update();
1440 return 0;
1443 //*****************************************************************************
1445 IMPL_STATIC_LINK( SvtFileDialog, FileNameModifiedHdl_Impl, void*, EMPTYARG )
1447 FileNameGetFocusHdl_Impl( pThis, NULL );
1448 return 0;
1451 //*****************************************************************************
1453 SvtFileDialogFilter_Impl* SvtFileDialog::FindFilter_Impl
1455 const String& _rFilter,
1456 sal_Bool _bMultiExt,/* TRUE - auch Filter mit mehreren Endungen
1457 beruecksichtigen
1458 FALSE - keine ...
1460 sal_Bool& _rFilterChanged
1463 /* [Beschreibung]
1465 Die Methode sucht in den eingef"ugten Filtern nach der
1466 spezifizierten Endung.
1470 SvtFileDialogFilter_Impl* pFoundFilter = NULL;
1471 SvtFileDialogFilterList_Impl* pList = _pImp->_pFilter;
1472 USHORT nFilter = pList->Count();
1474 while ( nFilter-- )
1476 SvtFileDialogFilter_Impl* pFilter = pList->GetObject( nFilter );
1477 const String& rType = pFilter->GetType();
1478 String aSingleType = rType;
1480 if ( _bMultiExt )
1482 USHORT nIdx = 0;
1483 while ( !pFoundFilter && nIdx != STRING_NOTFOUND )
1485 aSingleType = rType.GetToken( 0, FILEDIALOG_DEF_EXTSEP, nIdx );
1486 #ifdef UNX
1487 if ( aSingleType.CompareTo( _rFilter ) == COMPARE_EQUAL )
1488 #else
1489 if ( aSingleType.CompareIgnoreCaseToAscii( _rFilter ) == COMPARE_EQUAL )
1490 #endif
1491 pFoundFilter = pFilter;
1494 #ifdef UNX
1495 else if ( rType.CompareTo( _rFilter ) == COMPARE_EQUAL )
1496 #else
1497 else if ( rType.CompareIgnoreCaseToAscii( _rFilter ) == COMPARE_EQUAL )
1498 #endif
1499 pFoundFilter = pFilter;
1501 if ( pFoundFilter )
1503 // Filter aktivieren.
1504 _rFilterChanged = _pImp->_pUserFilter || ( _pImp->GetCurFilter() != pFilter );
1506 createNewUserFilter( _rFilter, sal_False );
1508 break;
1511 return pFoundFilter;
1514 //*****************************************************************************
1516 void SvtFileDialog::ExecuteFilter()
1518 _pImp->m_bNeedDelayedFilterExecute = sal_False;
1519 executeAsync( AsyncPickerAction::eExecuteFilter, String(), getMostCurrentFilter( _pImp ) );
1522 //*****************************************************************************
1524 void SvtFileDialog::OpenMultiSelection_Impl()
1526 /* [Beschreibung]
1528 OpenHandler f"ur MultiSelektion
1532 String aPath;
1533 ULONG nCount = _pFileView->GetSelectionCount();
1534 SvLBoxEntry* pEntry = nCount ? _pFileView->FirstSelected() : NULL;
1536 if ( nCount && pEntry )
1537 _aPath = _pFileView->GetURL( pEntry );
1539 // Interessenten benachrichtigen.
1540 long nRet;
1542 if ( _aOKHdl.IsSet() )
1543 nRet = _aOKHdl.Call( this );
1544 else
1545 nRet = OK();
1547 if ( nRet )
1548 EndDialog( TRUE );
1551 //*****************************************************************************
1553 void SvtFileDialog::UpdateControls( const String& rURL )
1555 _pImp->_pEdFileName->SetBaseURL( rURL );
1557 INetURLObject aObj( rURL );
1559 //=========================================================================
1561 String sText;
1562 DBG_ASSERT( INET_PROT_NOT_VALID != aObj.GetProtocol(), "SvtFileDialog::UpdateControls: Invalid URL!" );
1564 if ( aObj.getSegmentCount() )
1566 ::utl::LocalFileHelper::ConvertURLToSystemPath( rURL, sText );
1567 if ( sText.Len() )
1569 // no Fsys path for server file system ( only UCB has mountpoints! )
1570 if ( INET_PROT_FILE != aObj.GetProtocol() )
1571 sText = rURL.Copy( static_cast< USHORT >(
1572 INetURLObject::GetScheme( aObj.GetProtocol() ).getLength() ) );
1575 if ( !sText.Len() && aObj.getSegmentCount() )
1576 sText = rURL;
1579 // path mode ?
1580 if ( FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType )
1581 // -> set new path in the edit field
1582 _pImp->_pEdFileName->SetText( sText );
1584 // in the "current path" field, truncate the trailing slash
1585 if ( aObj.hasFinalSlash() )
1587 aObj.removeFinalSlash();
1588 String sURL( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1589 if ( !::utl::LocalFileHelper::ConvertURLToSystemPath( sURL, sText ) )
1590 sText = sURL;
1593 _pImp->_pFtCurrentPath->SetText( sText );
1596 //=========================================================================
1597 _aPath = rURL;
1598 if ( _pFileNotifier )
1599 _pFileNotifier->notify( DIRECTORY_CHANGED, 0 );
1602 //*****************************************************************************
1604 IMPL_LINK( SvtFileDialog, SelectHdl_Impl, SvTabListBox*, pBox )
1606 SvLBoxEntry* pEntry = pBox->FirstSelected();
1607 DBG_ASSERT( pEntry, "SelectHandler without selected entry" );
1608 SvtContentEntry* pUserData = (SvtContentEntry*)pEntry->GetUserData();
1610 if ( pUserData )
1612 INetURLObject aObj( pUserData->maURL );
1613 if ( FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType )
1615 if ( aObj.GetProtocol() == INET_PROT_FILE )
1617 if ( !pUserData->mbIsFolder )
1618 aObj.removeSegment();
1619 String aName = aObj.getFSysPath( (INetURLObject::FSysStyle)(INetURLObject::FSYS_DETECT & ~INetURLObject::FSYS_VOS) );
1620 _pImp->_pEdFileName->SetText( aName );
1621 _pImp->_pEdFileName->SetSelection( Selection( 0, aName.Len() ) );
1622 _aPath = pUserData->maURL;
1624 else if ( !pUserData->mbIsFolder )
1626 _pImp->_pEdFileName->SetText( pUserData->maURL );
1627 _pImp->_pEdFileName->SetSelection( Selection( 0, pUserData->maURL.Len() ) );
1628 _aPath = pUserData->maURL;
1630 else
1631 _pImp->_pEdFileName->SetText( UniString() );
1633 else
1635 if ( !pUserData->mbIsFolder )
1637 String aName = pBox->GetEntryText( pEntry, 0 );
1638 _pImp->_pEdFileName->SetText( aName );
1639 _pImp->_pEdFileName->SetSelection( Selection( 0, aName.Len() ) );
1640 _aPath = pUserData->maURL;
1645 if ( _pImp->_bMultiSelection && _pFileView->GetSelectionCount() > 1 )
1647 // bei Multiselektion den Datei-Edit leeren
1648 _pImp->_pEdFileName->SetText( String() );
1651 FileSelect();
1653 return 0;
1656 //*****************************************************************************
1658 IMPL_LINK( SvtFileDialog, DblClickHdl_Impl, SvTabListBox*, EMPTYARG )
1660 _pImp->_bDoubleClick = TRUE;
1661 OpenHdl_Impl( this, NULL );
1662 _pImp->_bDoubleClick = FALSE;
1664 return 0;
1667 //*****************************************************************************
1669 IMPL_LINK( SvtFileDialog, EntrySelectHdl_Impl, ComboBox*, EMPTYARG )
1671 FileSelect();
1673 return 0;
1676 //*****************************************************************************
1678 IMPL_LINK( SvtFileDialog, OpenDoneHdl_Impl, SvtFileView*, pView )
1680 String sCurrentFolder( pView->GetViewURL() );
1681 // check if we can create new folders
1682 EnableControl( _pImp->_pBtnNewFolder, ContentCanMakeFolder( sCurrentFolder ) && m_aURLFilter.isUrlAllowed( sCurrentFolder, false ) );
1684 // check if we can travel one level up
1685 bool bCanTravelUp = ContentHasParentFolder( pView->GetViewURL() );
1686 if ( bCanTravelUp )
1688 // additional check: the parent folder should not be prohibited
1689 INetURLObject aCurrentFolder( sCurrentFolder );
1690 DBG_ASSERT( INET_PROT_NOT_VALID != aCurrentFolder.GetProtocol(),
1691 "SvtFileDialog::OpenDoneHdl_Impl: invalid current URL!" );
1693 aCurrentFolder.removeSegment();
1694 bCanTravelUp &= m_aURLFilter.isUrlAllowed( aCurrentFolder.GetMainURL( INetURLObject::NO_DECODE ) );
1696 EnableControl( _pImp->_pBtnUp, bCanTravelUp );
1698 return 0;
1701 //*****************************************************************************
1703 IMPL_LINK( SvtFileDialog, AutoExtensionHdl_Impl, CheckBox*, EMPTYARG )
1705 if ( _pFileNotifier )
1706 _pFileNotifier->notify( CTRL_STATE_CHANGED,
1707 CHECKBOX_AUTOEXTENSION );
1709 // update the extension of the current file if necessary
1710 lcl_autoUpdateFileExtension( this, _pImp->GetCurFilter()->GetExtension() );
1712 return 0;
1715 //*****************************************************************************
1717 IMPL_LINK( SvtFileDialog, ClickHdl_Impl, CheckBox*, pCheckBox )
1719 if ( ! _pFileNotifier )
1720 return 0;
1722 sal_Int16 nId = -1;
1724 if ( pCheckBox == _pImp->_pCbOptions )
1725 nId = CHECKBOX_FILTEROPTIONS;
1726 else if ( pCheckBox == _pCbSelection )
1727 nId = CHECKBOX_SELECTION;
1728 else if ( pCheckBox == _pCbReadOnly )
1729 nId = CHECKBOX_READONLY;
1730 else if ( pCheckBox == _pImp->_pCbPassword )
1731 nId = CHECKBOX_PASSWORD;
1732 else if ( pCheckBox == _pCbLinkBox )
1733 nId = CHECKBOX_LINK;
1734 else if ( pCheckBox == _pCbPreviewBox )
1735 nId = CHECKBOX_PREVIEW;
1737 if ( nId != -1 )
1738 _pFileNotifier->notify( CTRL_STATE_CHANGED, nId );
1740 return 0;
1743 //*****************************************************************************
1745 IMPL_LINK( SvtFileDialog, PlayButtonHdl_Impl, PushButton*, EMPTYARG )
1747 if ( _pFileNotifier )
1748 _pFileNotifier->notify( CTRL_STATE_CHANGED,
1749 PUSHBUTTON_PLAY );
1751 return 0;
1754 //*****************************************************************************
1756 long SvtFileDialog::Notify( NotifyEvent& rNEvt )
1758 /* [Beschreibung]
1760 Die Methode wird gerufen, <BACKSPACE> abzufangen.
1764 USHORT nType = rNEvt.GetType();
1765 long nRet = 0;
1767 if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
1769 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1770 USHORT nCode = rKeyCode.GetCode();
1772 if ( !rKeyCode.GetModifier() &&
1773 KEY_BACKSPACE == nCode && !_pImp->_pEdFileName->HasChildPathFocus() )
1775 nRet = 0; //! (long)_pFileView->DoBeamerKeyInput( *rNEvt.GetKeyEvent() );
1777 if ( !nRet && _pImp->_pBtnUp->IsEnabled() )
1779 PrevLevel_Impl();
1780 nRet = 1;
1783 // else if ( rKeyCode.IsMod1() && ( KEY_C == nCode || KEY_V == nCode || KEY_X == nCode ) )
1784 // {
1785 /* (mhu)
1786 String aVerb = KEY_C == nCode ? UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_COPY)) :
1787 ( KEY_V == nCode ? UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_PASTE)) : UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_CUT)) );
1788 //(dv) if ( !CntPopupMenu::DoVerbCommand( aVerb, _pFileView->GetView() ) )
1789 //(dv) Sound::Beep();
1791 // }
1793 return nRet ? nRet : ModalDialog::Notify( rNEvt );
1796 //*****************************************************************************
1798 long SvtFileDialog::OK()
1800 return TRUE;
1803 //*****************************************************************************
1805 class SvtDefModalDialogParent_Impl
1807 private:
1808 Window* _pOld;
1810 public:
1811 SvtDefModalDialogParent_Impl( Window *pNew ) :
1812 _pOld( Application::GetDefDialogParent() )
1813 { Application::SetDefDialogParent( pNew ); }
1815 ~SvtDefModalDialogParent_Impl() { Application::SetDefDialogParent( _pOld ); }
1818 //*****************************************************************************
1820 //---------------------------------------------------------------------
1821 void SvtFileDialog::updateListboxLabelSizes()
1823 sal_Int16 nLineControlId[5] = {
1824 LISTBOX_VERSION, LISTBOX_TEMPLATE, LISTBOX_IMAGE_TEMPLATE, LISTBOX_FILTER, EDIT_FILEURL
1827 // determine the maximum width needed for the listbox labels
1828 long nMaxWidth = 0;
1829 for ( sal_Int32 i=0; i<5; ++i )
1831 FixedText* pLabel = static_cast< FixedText* >( getControl( nLineControlId[i], sal_True ) );
1832 if ( !pLabel )
1833 continue;
1834 nMaxWidth = ::std::max( pLabel->GetTextWidth( pLabel->GetText() ), nMaxWidth );
1837 // ensure that all labels are wide enough
1838 for ( sal_Int32 i=0; i<5; ++i )
1840 FixedText* pLabel = static_cast< FixedText* >( getControl( nLineControlId[i], sal_True ) );
1841 ListBox* pListbox = static_cast< ListBox* >( getControl( nLineControlId[i], sal_False ) );
1842 if ( !pLabel || !pListbox )
1843 continue;
1844 Size aCurrentSize( pLabel->GetSizePixel() );
1845 if ( aCurrentSize.Width() >= nMaxWidth )
1846 continue;
1848 long nChange = nMaxWidth - aCurrentSize.Width();
1849 pLabel->SetSizePixel( Size( nMaxWidth, aCurrentSize.Height() ) );
1851 aCurrentSize = pListbox->GetSizePixel();
1852 pListbox->SetSizePixel( Size( aCurrentSize.Width() - nChange, aCurrentSize.Height() ) );
1853 lcl_MoveControl( pListbox, nChange, 0 );
1857 namespace
1860 bool implIsInvalid( const String & rURL )
1862 SmartContent aContent( rURL );
1863 aContent.enableOwnInteractionHandler( ::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST );
1864 aContent.isFolder(); // do this _before_ asking isInvalid! Otherwise result might be wrong.
1865 return aContent.isInvalid();
1870 //---------------------------------------------------------------------
1871 String SvtFileDialog::implGetInitialURL( const String& _rPath, const String& _rFallback )
1873 // an URL parser for the fallback
1874 INetURLObject aURLParser;
1876 // set the path
1877 bool bWasAbsolute = FALSE;
1878 aURLParser = aURLParser.smartRel2Abs( _rPath, bWasAbsolute );
1880 // is it a valid folder?
1881 m_aContent.bindTo( aURLParser.GetMainURL( INetURLObject::NO_DECODE ) );
1882 sal_Bool bIsFolder = m_aContent.isFolder( ); // do this _before_ asking isInvalid!
1883 sal_Bool bIsInvalid = m_aContent.isInvalid();
1885 if ( bIsInvalid && m_bHasFilename && !aURLParser.hasFinalSlash() )
1886 { // check if the parent folder exists
1887 // #108429# - 2003-03-26 - fs@openoffice.org
1888 INetURLObject aParent( aURLParser );
1889 aParent.removeSegment( );
1890 aParent.setFinalSlash( );
1891 bIsInvalid = implIsInvalid( aParent.GetMainURL( INetURLObject::NO_DECODE ) );
1894 if ( bIsInvalid )
1896 INetURLObject aFallback( _rFallback );
1897 bIsInvalid = implIsInvalid( aFallback.GetMainURL( INetURLObject::NO_DECODE ) );
1899 if ( !bIsInvalid )
1900 aURLParser = aFallback;
1903 if ( bIsInvalid )
1905 INetURLObject aParent( aURLParser );
1906 while ( bIsInvalid && aParent.removeSegment() )
1908 aParent.setFinalSlash( );
1909 bIsInvalid = implIsInvalid( aParent.GetMainURL( INetURLObject::NO_DECODE ) );
1912 if ( !bIsInvalid )
1913 aURLParser = aParent;
1916 if ( !bIsInvalid && bIsFolder )
1918 aURLParser.setFinalSlash();
1920 return aURLParser.GetMainURL( INetURLObject::NO_DECODE );
1923 //---------------------------------------------------------------------
1924 short SvtFileDialog::Execute()
1926 if ( !PrepareExecute() )
1927 return 0;
1929 // Start des Dialogs.
1930 _bIsInExecute = TRUE;
1931 short nResult = ModalDialog::Execute();
1932 _bIsInExecute = FALSE;
1934 DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFilePicker::Execute: still running an async action!" );
1935 // the dialog should not be cancellable while an async action is running - firs, the action
1936 // needs to be cancelled
1938 // letztes Verzeichnis merken
1939 if ( RET_OK == nResult )
1941 INetURLObject aURL( _aPath );
1942 if ( aURL.GetProtocol() == INET_PROT_FILE )
1944 // nur bei File-URL's und nicht bei virtuelle Folder
1945 // das ausgew"ahlte Verzeichnis merken
1946 sal_Int32 nLevel = aURL.getSegmentCount();
1947 // #97148# & #102204# ------
1948 sal_Bool bDir = m_aContent.isFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1949 // BOOL bClassPath = ( ( _pImp->_nStyle & SFXWB_CLASSPATH ) == SFXWB_CLASSPATH );
1950 if ( nLevel > 1 && ( FILEDLG_TYPE_FILEDLG == _pImp->_eDlgType || !bDir ) )
1951 aURL.removeSegment();
1955 return nResult;
1958 //---------------------------------------------------------------------
1959 void SvtFileDialog::StartExecuteModal( const Link& rEndDialogHdl )
1961 PrepareExecute();
1963 // Start des Dialogs.
1964 // _bIsInExecute = TRUE;
1965 ModalDialog::StartExecuteModal( rEndDialogHdl );
1968 //-----------------------------------------------------------------------------
1969 void SvtFileDialog::onAsyncOperationStarted()
1971 EnableUI( FALSE );
1972 // the cancel button must be always enabled
1973 _pImp->_pBtnCancel->Enable( TRUE );
1974 _pImp->_pBtnCancel->GrabFocus();
1977 //-----------------------------------------------------------------------------
1978 void SvtFileDialog::onAsyncOperationFinished()
1980 EnableUI( TRUE );
1981 m_pCurrentAsyncAction = NULL;
1982 if ( !m_bInExecuteAsync )
1983 _pImp->_pEdFileName->GrabFocus();
1984 // (if m_bInExecuteAsync is true, then the operation was finished within the minium wait time,
1985 // and to the user, the operation appears to be synchronous)
1988 //-------------------------------------------------------------------------
1989 void SvtFileDialog::displayIOException( const String& _rURL, IOErrorCode _eCode )
1993 // create make a human-readable string from the URL
1994 String sDisplayPath( _rURL );
1995 ::utl::LocalFileHelper::ConvertURLToSystemPath( _rURL, sDisplayPath );
1997 // build an own exception which tells "access denied"
1998 InteractiveAugmentedIOException aException;
1999 aException.Arguments.realloc( 2 );
2000 aException.Arguments[ 0 ] <<= ::rtl::OUString( sDisplayPath );
2001 aException.Arguments[ 1 ] <<= PropertyValue(
2002 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ),
2003 -1, aException.Arguments[ 0 ], PropertyState_DIRECT_VALUE
2005 // (formerly, it was sufficient to put the URL first parameter. Nowadays,
2006 // the services expects the URL in a PropertyValue named "Uri" ...)
2007 aException.Code = _eCode;
2008 aException.Classification = InteractionClassification_ERROR;
2010 // let and interaction handler handle this exception
2011 ::comphelper::OInteractionRequest* pRequest = NULL;
2012 Reference< ::com::sun::star::task::XInteractionRequest > xRequest = pRequest =
2013 new ::comphelper::OInteractionRequest( makeAny( aException ) );
2014 pRequest->addContinuation( new ::comphelper::OInteractionAbort( ) );
2016 Reference< XInteractionHandler > xHandler(
2017 ::comphelper::getProcessServiceFactory()->createInstance(
2018 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") )
2020 UNO_QUERY
2022 if ( xHandler.is() )
2023 xHandler->handle( xRequest );
2025 catch( const Exception& )
2027 DBG_ERROR( "iodlg::displayIOException: caught an exception!" );
2031 //-----------------------------------------------------------------------------
2032 void SvtFileDialog::EnableUI( BOOL _bEnable )
2034 Enable( _bEnable );
2036 if ( _bEnable )
2038 for ( ::std::set< Control* >::iterator aLoop = m_aDisabledControls.begin();
2039 aLoop != m_aDisabledControls.end();
2040 ++aLoop
2043 (*aLoop)->Enable( FALSE );
2048 //-----------------------------------------------------------------------------
2049 void SvtFileDialog::EnableControl( Control* _pControl, BOOL _bEnable )
2051 if ( !_pControl )
2053 DBG_ERRORFILE( "SvtFileDialog::EnableControl: invalid control!" );
2054 return;
2057 _pControl->Enable( _bEnable );
2059 if ( _bEnable )
2061 ::std::set< Control* >::iterator aPos = m_aDisabledControls.find( _pControl );
2062 if ( m_aDisabledControls.end() != aPos )
2063 m_aDisabledControls.erase( aPos );
2065 else
2066 m_aDisabledControls.insert( _pControl );
2069 //----------------------------------------------------------------------------
2071 short SvtFileDialog::PrepareExecute()
2073 rtl::OUString aEnvValue;
2074 if ( getEnvironmentValue( "WorkDirMustContainRemovableMedia", aEnvValue ) &&
2075 aEnvValue.equalsAscii( "1" ) )
2079 INetURLObject aStdDir( GetStandardDir() );
2080 ::ucbhelper::Content aCnt( rtl::OUString( aStdDir.GetMainURL(
2081 INetURLObject::NO_DECODE ) ),
2082 Reference< XCommandEnvironment >() );
2083 Sequence< rtl::OUString > aProps(2);
2084 aProps[0] = rtl::OUString::createFromAscii( "IsVolume" );
2085 aProps[1] = rtl::OUString::createFromAscii( "IsRemoveable" );
2087 Reference< XResultSet > xResultSet
2088 = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_ONLY );
2089 if ( xResultSet.is() )
2091 Reference< XRow > xRow( xResultSet, UNO_QUERY );
2093 bool bEmpty = true;
2094 if ( !xResultSet->next() )
2096 // folder is empty
2097 bEmpty = true;
2099 else
2101 // @@@ KSO 05/18/2006: support for removable media currently hardcoded/incomplete in OSL
2103 // do
2104 // {
2105 // // check, whether child is a removable volume
2106 // if ( xRow->getBoolean( 1 ) && !xRow->wasNull() )
2107 // {
2108 // if ( xRow->getBoolean( 2 ) && !xRow->wasNull() )
2109 // {
2110 bEmpty = false;
2111 // break;
2112 // }
2113 // }
2114 // }
2115 // while ( xResultSet->next() );
2118 if ( bEmpty )
2120 ErrorBox aBox( this, WB_OK, SvtResId( STR_SVT_NOREMOVABLEDEVICE ) );
2121 aBox.Execute();
2122 return 0;
2126 catch ( ContentCreationException const & )
2129 catch ( CommandAbortedException const & )
2134 // #102204# ---------------
2135 if ( ( _pImp->_nStyle & WB_SAVEAS ) && m_bHasFilename )
2136 // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2137 // - finally we're going to save that file, aren't we?
2138 // #105812# - 2002-12-02 - fs@openoffice.org
2139 m_aContent.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST);
2140 else
2141 m_aContent.enableDefaultInteractionHandler();
2143 // #53016# evtl. nur ein Filename ohne Pfad?
2144 String aFileNameOnly;
2145 if( _aPath.Len() && (_pImp->_eMode == FILEDLG_MODE_SAVE)
2146 && (_aPath.Search(':') == STRING_NOTFOUND)
2147 && (_aPath.Search('\\') == STRING_NOTFOUND)
2148 && (_aPath.Search('/') == STRING_NOTFOUND))
2150 aFileNameOnly = _aPath;
2151 _aPath.Erase();
2154 // kein Startpfad angegeben?
2155 if ( !_aPath.Len() )
2157 // dann das Standard-Dir verwenden
2158 _aPath = lcl_ensureFinalSlash( _pImp->GetStandardDir() );
2160 // #53016# vorgegebener Dateiname an Pfad anh"angen
2161 if ( aFileNameOnly.Len() )
2162 _aPath += aFileNameOnly;
2165 //.....................................................................
2166 _aPath = implGetInitialURL( _aPath, GetStandardDir() );
2168 if ( _pImp->_nStyle & WB_SAVEAS && !m_bHasFilename )
2169 // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2170 // - finally we're going to save that file, aren't we?
2171 m_aContent.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST);
2173 //.....................................................................
2174 // care for possible restrictions on the paths we're allowed to show
2175 if ( !m_aURLFilter.isUrlAllowed( _aPath ) )
2176 _aPath = m_aURLFilter.getFilter()[0];
2178 // Ggf. Filter anzeigen.
2179 _pImp->InitFilterList();
2181 // Initialen Filter einstellen.
2182 USHORT nFilterCount = GetFilterCount();
2183 String aAll( SvtResId( STR_FILTERNAME_ALL ) );
2184 BOOL bHasAll = _pImp->HasFilterListEntry( aAll );
2185 if ( _pImp->GetCurFilter() || nFilterCount == 1 || ( nFilterCount == 2 && bHasAll ) )
2187 // Ggf. einzigen Filter als aktuellen Filter setzen oder den einzigen
2188 // Filter, der nicht auf alle Dateien verweist.
2189 if ( !_pImp->GetCurFilter() )
2191 USHORT nPos = 0;
2192 if ( 2 == nFilterCount && bHasAll )
2194 nPos = nFilterCount;
2195 while ( nPos-- )
2197 if ( GetFilterName( nPos ) != aAll )
2198 break;
2201 SvtFileDialogFilter_Impl* pNewCurFilter = _pImp->_pFilter->GetObject( nPos );
2202 DBG_ASSERT( pNewCurFilter, "SvtFileDialog::Execute: invalid filter pos!" );
2203 _pImp->SetCurFilter( pNewCurFilter, pNewCurFilter->GetName() );
2206 // Anzeige anpassen.
2207 _pImp->SelectFilterListEntry( _pImp->GetCurFilter()->GetName() );
2208 SetDefaultExt( _pImp->GetCurFilter()->GetExtension() );
2209 USHORT nSepPos = GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP );
2210 if ( nSepPos != STRING_NOTFOUND )
2211 EraseDefaultExt( nSepPos );
2213 else
2215 // Ggf. Filter fuer alle Dateien setzen bzw. erzeugen.
2216 if ( !bHasAll )
2218 SvtFileDialogFilter_Impl* pAllFilter = implAddFilter( aAll, UniString(RTL_CONSTASCII_USTRINGPARAM(FILEDIALOG_FILTER_ALL)) );
2219 _pImp->InsertFilterListEntry( pAllFilter );
2220 _pImp->SetCurFilter( pAllFilter, aAll );
2222 _pImp->SelectFilterListEntry( aAll );
2225 _pImp->_pDefaultFilter = _pImp->GetCurFilter();
2227 // HACK #50065#
2228 // ggf. Filter isolieren.
2229 String aFilter;
2231 if ( !IsolateFilterFromPath_Impl( _aPath, aFilter ) )
2232 return 0;
2234 sal_uInt16 nNewFilterFlags = adjustFilter( aFilter );
2235 if ( nNewFilterFlags & ( FLT_NONEMPTY | FLT_USERFILTER ) )
2237 _pImp->_pEdFileName->SetText( aFilter );
2239 // HACK #50065#
2241 // Instanz fuer den gesetzten Pfad erzeugen und anzeigen.
2242 INetURLObject aFolderURL( _aPath );
2243 String aFileName( aFolderURL.getName( INetURLObject::LAST_SEGMENT, false ) );
2244 xub_StrLen nFileNameLen = aFileName.Len();
2245 bool bFileToSelect = nFileNameLen != 0;
2246 if ( bFileToSelect && aFileName.GetChar( nFileNameLen - 1 ) != INET_PATH_TOKEN )
2248 _pImp->_pEdFileName->SetText( GET_DECODED_NAME( aFolderURL ) );
2249 aFolderURL.removeSegment();
2252 INetURLObject aObj = aFolderURL;
2253 if ( aObj.GetProtocol() == INET_PROT_FILE )
2255 // Ordner als aktuelles Verzeichnis setzen.
2256 aObj.setFinalSlash();
2259 UpdateControls( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2261 // Somebody might want to enable some controls acording to the current filter
2262 FilterSelect();
2264 // Zustand der Steuerelemente anpassen.
2265 // EndListeningAll();
2267 ViewHdl_Impl( this, NULL );
2268 OpenURL_Impl( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2270 _pFileView->Show();
2271 SvtDefModalDialogParent_Impl aDefParent( this );
2273 // ggf. Gr"osse aus Ini lesen und setzen
2274 InitSize();
2276 return 1;
2279 //-----------------------------------------------------------------------------
2280 void SvtFileDialog::implInitializeSpecialURLLists( )
2282 m_aURLFilter = ::svt::RestrictedPaths();
2284 ::std::vector< String > aFavourites;
2285 if ( m_aURLFilter.hasFilter() )
2287 // if we have restrictions, then the "favourites" are the restricted folders only
2288 aFavourites = m_aURLFilter.getFilter();
2289 // for approved URLs, we needed the final slashes, for
2290 // favourites, we do not want to have them
2291 ::std::for_each( aFavourites.begin(), aFavourites.end(), RemoveFinalSlash() );
2293 else
2295 ::rtl::OUString sFavouritesList;
2296 if ( getEnvironmentValue( "PathFavourites", sFavouritesList ) )
2297 convertStringListToUrls( sFavouritesList, aFavourites, false );
2300 DBG_ASSERT( _pImp->_pBtnStandard, "SvtFileDialog::implInitializeSpecialURLLists: how this?" );
2301 if ( _pImp->_pBtnStandard )
2302 _pImp->_pBtnStandard->SetFavouriteLocations( aFavourites );
2305 //-----------------------------------------------------------------------------
2306 void SvtFileDialog::executeAsync( ::svt::AsyncPickerAction::Action _eAction,
2307 const String& _rURL, const String& _rFilter )
2309 DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );
2311 m_pCurrentAsyncAction = new AsyncPickerAction( this, _pFileView, _eAction );
2313 bool bReallyAsync = true;
2314 m_aConfiguration.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillAsynchronously" ) ) ) >>= bReallyAsync;
2316 sal_Int32 nMinTimeout = 0;
2317 m_aConfiguration.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Timeout/Min" ) ) ) >>= nMinTimeout;
2318 sal_Int32 nMaxTimeout = 0;
2319 m_aConfiguration.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Timeout/Max" ) ) ) >>= nMaxTimeout;
2321 m_bInExecuteAsync = true;
2322 m_pCurrentAsyncAction->execute( _rURL, _rFilter, bReallyAsync ? nMinTimeout : -1, nMaxTimeout, GetBlackList() );
2323 m_bInExecuteAsync = false;
2326 //*****************************************************************************
2328 void SvtFileDialog::FileSelect()
2330 if ( _pFileNotifier )
2331 _pFileNotifier->notify( FILE_SELECTION_CHANGED, 0 );
2334 //*****************************************************************************
2336 void SvtFileDialog::FilterSelect()
2338 if ( _pFileNotifier )
2339 _pFileNotifier->notify( CTRL_STATE_CHANGED,
2340 LISTBOX_FILTER );
2343 //*****************************************************************************
2345 void SvtFileDialog::SetStandardDir( const String& rStdDir )
2347 /* [Beschreibung]
2349 Die Methode setzt den Pfad f"ur den Standardknopf.
2353 INetURLObject aObj( rStdDir );
2354 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid protocol!" );
2355 aObj.setFinalSlash();
2356 _pImp->SetStandardDir( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2359 void SvtFileDialog::SetBlackList( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
2361 _pImp->SetBlackList( rBlackList );
2364 //*****************************************************************************
2366 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& SvtFileDialog::GetBlackList() const
2368 return _pImp->GetBlackList();
2370 //*****************************************************************************
2372 const String& SvtFileDialog::GetStandardDir() const
2374 /* [Beschreibung]
2376 Diese Methode gibt den eingestellten Standardpfad zur"uck.
2380 return _pImp->GetStandardDir();
2383 //*****************************************************************************
2385 void SvtFileDialog::PrevLevel_Impl()
2387 _pFileView->EndInplaceEditing( false );
2389 String sDummy;
2390 executeAsync( AsyncPickerAction::ePrevLevel, sDummy, sDummy );
2393 //*****************************************************************************
2395 void SvtFileDialog::OpenURL_Impl( const String& _rURL )
2397 _pFileView->EndInplaceEditing( false );
2399 DBG_ASSERT( m_aURLFilter.isUrlAllowed( _rURL ), "SvtFileDialog::OpenURL_Impl: forbidden URL! Should have been handled by the caller!" );
2400 executeAsync( AsyncPickerAction::eOpenURL, _rURL, getMostCurrentFilter( _pImp ) );
2403 //*****************************************************************************
2404 SvtFileDialogFilter_Impl* SvtFileDialog::implAddFilter( const String& _rFilter, const String& _rType )
2406 SvtFileDialogFilter_Impl* pNewFilter = new SvtFileDialogFilter_Impl( _rFilter, _rType );
2407 _pImp->_pFilter->C40_INSERT( SvtFileDialogFilter_Impl, pNewFilter, (USHORT)0 );
2409 if ( !_pImp->GetCurFilter() )
2410 _pImp->SetCurFilter( pNewFilter, _rFilter );
2412 return pNewFilter;
2415 //*****************************************************************************
2417 void SvtFileDialog::AddFilter( const String& _rFilter, const String& _rType )
2419 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2420 implAddFilter ( _rFilter, _rType );
2423 //*****************************************************************************
2424 void SvtFileDialog::AddFilterGroup( const String& _rFilter, const Sequence< StringPair >& _rFilters )
2426 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2428 implAddFilter( _rFilter, String() );
2429 const StringPair* pSubFilters = _rFilters.getConstArray();
2430 const StringPair* pSubFiltersEnd = pSubFilters + _rFilters.getLength();
2431 for ( ; pSubFilters != pSubFiltersEnd; ++pSubFilters )
2432 implAddFilter( pSubFilters->First, pSubFilters->Second );
2435 //*****************************************************************************
2437 //-----------------------------------------------------------------------------
2438 void SvtFileDialog::SetCurFilter( const String& rFilter )
2440 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::SetCurFilter: currently executing!" );
2442 // Entsprechenden Filter suchen.
2443 USHORT nPos = _pImp->_pFilter->Count();
2445 while ( nPos-- )
2447 SvtFileDialogFilter_Impl* pFilter = _pImp->_pFilter->GetObject( nPos );
2448 if ( pFilter->GetName() == rFilter )
2450 _pImp->SetCurFilter( pFilter, rFilter );
2451 break;
2456 //*****************************************************************************
2458 String SvtFileDialog::GetCurFilter() const
2460 String aFilter;
2462 const SvtFileDialogFilter_Impl* pCurrentFilter = _pImp->GetCurFilter();
2463 if ( pCurrentFilter )
2464 aFilter = pCurrentFilter->GetName();
2466 return aFilter;
2469 String SvtFileDialog::getCurFilter( ) const
2471 return GetCurFilter();
2474 //*****************************************************************************
2476 USHORT SvtFileDialog::GetFilterCount() const
2478 return _pImp->_pFilter->Count();
2481 //*****************************************************************************
2483 const String& SvtFileDialog::GetFilterName( USHORT nPos ) const
2485 DBG_ASSERT( nPos < GetFilterCount(), "invalid index" );
2486 return _pImp->_pFilter->GetObject( nPos )->GetName();
2489 //*****************************************************************************
2491 void SvtFileDialog::InitSize()
2493 if ( ! _pImp->_aIniKey.Len() )
2494 return;
2496 Size aDlgSize = GetResizeOutputSizePixel();
2497 SetMinOutputSizePixel( aDlgSize );
2499 if ( !_pImp->_nFixDeltaHeight )
2501 // Fixgr"ossen errechnen und merken
2502 Point aPnt = _pFileView->GetPosPixel();
2503 long nBoxH = _pFileView->GetSizePixel().Height();
2504 long nH = GetSizePixel().Height();
2505 _pImp->_nFixDeltaHeight = nH - nBoxH;
2508 // initialize from config
2509 SvtViewOptions aDlgOpt( E_DIALOG, _pImp->_aIniKey );
2511 if ( aDlgOpt.Exists() )
2513 SetWindowState( ByteString( String( aDlgOpt.GetWindowState() ), osl_getThreadTextEncoding() ) );
2515 Any aUserData = aDlgOpt.GetUserItem( ::rtl::OUString::createFromAscii( "UserData" ) );
2516 ::rtl::OUString sCfgStr;
2517 if ( aUserData >>= sCfgStr )
2518 _pFileView->SetConfigString( String( sCfgStr ) );
2522 //*****************************************************************************
2524 SvStringsDtor* SvtFileDialog::GetPathList() const
2526 SvStringsDtor* pList = new SvStringsDtor;
2527 ULONG nCount = _pFileView->GetSelectionCount();
2528 SvLBoxEntry* pEntry = nCount ? _pFileView->FirstSelected() : NULL;
2530 if ( ! pEntry )
2532 String* pURL;
2534 if ( _pImp->_pEdFileName->GetText().Len() && _bIsInExecute )
2535 pURL = new String( _pImp->_pEdFileName->GetURL() );
2536 else
2537 pURL = new String( _aPath );
2539 pList->Insert( pURL, pList->Count() );
2541 else
2543 while ( pEntry )
2545 String* pURL = new String( _pFileView->GetURL( pEntry ) );
2546 pList->Insert( pURL, pList->Count() );
2547 pEntry = _pFileView->NextSelected( pEntry );
2551 return pList;
2554 //*****************************************************************************
2556 void SvtFileDialog::implArrangeControls()
2558 // this is the list of controls in the order they should be tabbed
2559 // from topleft to bottomright
2560 // pb: #136070# new order so all LabeledBy relations are correct now
2561 Control* pControls[] =
2563 _pImp->_pFtCurrentPath,
2564 _pImp->_pBtnUp, _pImp->_pBtnNewFolder, _pImp->_pBtnStandard, // image buttons
2565 _pFileView, // the file view
2566 _pImp->_pFtFileName, _pImp->_pEdFileName,
2567 _pImp->_pFtFileVersion, _pImp->_pLbFileVersion,
2568 _pImp->_pFtTemplates, _pImp->_pLbTemplates,
2569 _pImp->_pFtImageTemplates, _pImp->_pLbImageTemplates,
2570 _pImp->_pFtFileType, _pImp->GetFilterListControl(), // edit fields/list boxes
2571 _pImp->_pCbPassword, _pImp->_pCbAutoExtension, _pImp->_pCbOptions, // checkboxes
2572 _pCbReadOnly, _pCbLinkBox, _pCbPreviewBox, _pCbSelection, _pPbPlay, // check boxes (continued)
2573 _pImp->_pBtnFileOpen, _pImp->_pBtnCancel, _pImp->_pBtnHelp // buttons
2575 // (including the FixedTexts is important - not for tabbing order (they're irrelevant there),
2576 // but for working keyboard shortcuts)
2577 // 96861 - 23.01.2002 - fs@openoffice.org
2580 // loop through all these controls and adjust the z-order
2581 Window* pPreviousWin = NULL;
2582 Control** pCurrent = pControls;
2583 for ( sal_Int32 i = 0; i < sal_Int32(sizeof( pControls ) / sizeof( pControls[ 0 ] )); ++i, ++pCurrent )
2585 if ( !*pCurrent )
2586 // this control is not available in the current operation mode -> skip
2587 continue;
2589 if ( pPreviousWin )
2590 (*pCurrent)->SetZOrder( pPreviousWin, WINDOW_ZORDER_BEHIND );
2591 else
2592 (*pCurrent)->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
2594 pPreviousWin = *pCurrent;
2597 // FileName edit not the first control but it should have the focus initially
2598 _pImp->_pEdFileName->GrabFocus();
2601 //*****************************************************************************
2603 BOOL SvtFileDialog::IsolateFilterFromPath_Impl( String& rPath, String& rFilter )
2605 String aEmpty;
2606 String aReversePath( rPath );
2607 aReversePath.Reverse();
2608 USHORT nQuestionMarkPos = rPath.Search( '?' );
2610 if ( nQuestionMarkPos != STRING_NOTFOUND )
2612 // Fragezeichen als Wildcard nur bei Files
2613 INetProtocol eProt = INetURLObject::CompareProtocolScheme( rPath );
2615 if ( INET_PROT_NOT_VALID != eProt && INET_PROT_FILE != eProt )
2616 nQuestionMarkPos = STRING_NOTFOUND;
2618 USHORT nWildCardPos = Min( rPath.Search( FILEDIALOG_DEF_WILDCARD ), nQuestionMarkPos );
2619 rFilter = aEmpty;
2621 if ( nWildCardPos != STRING_NOTFOUND )
2623 USHORT nPathTokenPos = aReversePath.Search( INET_PATH_TOKEN );
2625 if ( nPathTokenPos == STRING_NOTFOUND )
2627 String aDelim(
2628 #if defined(WNT) || defined(OS2)
2629 '\\'
2630 #else
2632 #endif
2635 nPathTokenPos = aReversePath.Search( aDelim );
2636 #if defined(OS2)
2637 if ( nPathTokenPos == STRING_NOTFOUND )
2639 nPathTokenPos = aReversePath.Search( '/' );
2641 #endif
2642 #if !defined( UNX )
2643 if ( nPathTokenPos == STRING_NOTFOUND )
2645 nPathTokenPos = aReversePath.Search( ':' );
2647 #endif
2650 // Syntax pr"ufen.
2651 if ( nPathTokenPos != STRING_NOTFOUND )
2653 if ( nPathTokenPos < (rPath.Len() - nWildCardPos - 1) )
2655 ErrorHandler::HandleError( ERRCODE_SFX_INVALIDSYNTAX );
2656 return FALSE;
2659 // Filter abschneiden.
2660 rFilter = aReversePath;
2661 rFilter.Erase( nPathTokenPos );
2662 rFilter.Reverse();
2664 // Ordner bestimmen.
2665 rPath = aReversePath;
2666 rPath.Erase( 0, nPathTokenPos );
2667 rPath.Reverse();
2669 else
2671 rFilter = rPath;
2672 rPath = aEmpty;
2676 return TRUE;
2679 //*****************************************************************************
2681 //-----------------------------------------------------------------------------
2682 void SvtFileDialog::implUpdateImages( )
2684 // determine high contrast mode
2686 sal_Bool bIsHighContrast = GetDisplayBackground().GetColor().IsDark();
2687 m_aImages = ImageList( SvtResId( bIsHighContrast ? RID_FILEPICKER_IMAGES_HC : RID_FILEPICKER_IMAGES ) );
2690 // set the appropriate images on the buttons
2691 if ( _pImp->_pBtnUp )
2692 _pImp->_pBtnUp->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_UP ) );
2694 if ( _pImp->_pBtnStandard )
2695 _pImp->_pBtnStandard->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_STD ) );
2697 if ( _pImp->_pBtnNewFolder )
2698 _pImp->_pBtnNewFolder->SetModeImage( GetButtonImage( IMG_FILEDLG_CREATEFOLDER ) );
2701 //-----------------------------------------------------------------------------
2702 void SvtFileDialog::DataChanged( const DataChangedEvent& _rDCEvt )
2704 if ( DATACHANGED_SETTINGS == _rDCEvt.GetType() )
2705 implUpdateImages( );
2707 ModalDialog::DataChanged( _rDCEvt );
2710 //-----------------------------------------------------------------------------
2711 void SvtFileDialog::Resize()
2713 if ( IsRollUp() )
2714 return;
2716 Size aDlgSize = GetResizeOutputSizePixel();
2717 Size aOldSize = _pImp->_aDlgSize;
2718 _pImp->_aDlgSize = aDlgSize;
2719 long nWinDeltaW = 0;
2721 if ( _pPrevWin &&
2722 _pPrevWin->GetPosPixel().X() > _pFileView->GetPosPixel().X() )
2724 nWinDeltaW = _pPrevWin->GetOutputSizePixel().Width() + _pImp->_a6Size.Width();
2727 Size aNewSize = _pFileView->GetSizePixel();
2728 Point aBoxPos( _pFileView->GetPosPixel() );
2729 long nDeltaY = aNewSize.Height();
2730 long nDeltaX = aNewSize.Width();
2731 aNewSize.Height() = aDlgSize.Height() - _pImp->_nFixDeltaHeight;
2732 aNewSize.Width() = aDlgSize.Width() - aBoxPos.X() - _pImp->_a6Size.Width() - nWinDeltaW;
2733 if ( aOldSize.Height() )
2734 nDeltaY = _pImp->_aDlgSize.Height() - aOldSize.Height();
2735 else
2736 nDeltaY = aNewSize.Height() - nDeltaY;
2737 nDeltaX = aNewSize.Width() - nDeltaX;
2739 if ( nWinDeltaW )
2740 nWinDeltaW = nDeltaX * 2 / 3;
2741 aNewSize.Width() -= nWinDeltaW;
2742 nDeltaX -= nWinDeltaW;
2744 _pFileView->SetSizePixel( aNewSize );
2746 if ( !nDeltaY && !nDeltaX )
2747 // Dieses Resize wurde nur zum Ein - oder Ausblenden des Indicators aufgerufen
2748 return;
2750 // -------------
2751 // move controls
2753 // controls to move vertically
2755 Control* aMoveControlsVert[] =
2757 _pImp->_pFtFileName, _pImp->_pEdFileName, _pImp->_pFtFileVersion, _pImp->_pLbFileVersion,
2758 _pImp->_pFtTemplates, _pImp->_pLbTemplates, _pImp->_pFtImageTemplates, _pImp->_pLbImageTemplates,
2759 _pImp->_pFtFileType, _pImp->GetFilterListControl(), _pCbReadOnly, _pCbLinkBox, _pCbPreviewBox,
2760 _pPbPlay, _pImp->_pCbPassword, _pImp->_pCbAutoExtension, _pImp->_pCbOptions, _pCbSelection
2762 Control** ppMoveControls = aMoveControlsVert;
2763 Control** ppMoveControlsEnd = ppMoveControls + sizeof( aMoveControlsVert ) / sizeof( aMoveControlsVert[0] );
2764 for ( ; ppMoveControls != ppMoveControlsEnd; ++ppMoveControls )
2765 lcl_MoveControl( *ppMoveControls, 0, nDeltaY );
2768 // controls to move vertically and horizontally
2770 Control* aMoveControlsBoth[] =
2772 _pImp->_pBtnFileOpen, _pImp->_pBtnCancel, _pImp->_pBtnHelp
2774 Control** ppMoveControls = aMoveControlsBoth;
2775 Control** ppMoveControlsEnd = ppMoveControls + sizeof( aMoveControlsBoth ) / sizeof( aMoveControlsBoth[0] );
2776 for ( ; ppMoveControls != ppMoveControlsEnd; ++ppMoveControls )
2777 lcl_MoveControl( *ppMoveControls, nDeltaX, nDeltaY );
2780 // controls to move horizontally
2782 Control* aMoveControlsHor[] =
2784 _pImp->_pBtnUp, _pImp->_pBtnNewFolder, _pImp->_pBtnStandard
2786 Control** ppMoveControls = aMoveControlsHor;
2787 Control** ppMoveControlsEnd = ppMoveControls + sizeof( aMoveControlsHor ) / sizeof( aMoveControlsHor[0] );
2788 for ( ; ppMoveControls != ppMoveControlsEnd; ++ppMoveControls )
2789 lcl_MoveControl( *ppMoveControls, nDeltaX, 0 );
2792 // ---------------
2793 // resize controls
2795 Control* aSizeControls[] =
2797 _pImp->_pEdFileName, _pImp->_pLbFileVersion, _pImp->_pLbTemplates, _pImp->_pLbImageTemplates,
2798 _pImp->GetFilterListControl(), _pImp->_pFtCurrentPath,
2800 sal_Int32 nSizeControls = sizeof( aSizeControls ) / sizeof( aSizeControls[0] );
2801 Control** ppSizeControls = aSizeControls;
2802 for ( sal_Int32 j=0; j<nSizeControls; ++j, ++ppSizeControls )
2804 if ( *ppSizeControls )
2806 aNewSize = (*ppSizeControls)->GetSizePixel();
2807 aNewSize.Width() += nDeltaX;
2808 (*ppSizeControls)->SetSizePixel( aNewSize );
2813 // zus"atzliche Controls ausrichten
2814 if ( _pPrevWin &&
2815 _pPrevWin->GetPosPixel().X() > _pFileView->GetPosPixel().X() )
2817 // Controls vom Typ Window speziell ausrichten
2818 // auch die Gr"osse anpassen
2819 Point aNewPos = _pPrevWin->GetPosPixel();
2820 aNewPos.X() += nDeltaX;
2821 _pPrevWin->SetPosPixel( aNewPos );
2822 _pPrevBmp->SetPosPixel( aNewPos );
2823 aNewSize = _pPrevWin->GetOutputSizePixel();
2824 aNewSize.Width() += nWinDeltaW;
2825 aNewSize.Height() += nDeltaY;
2826 if ( !aOldSize.Height() )
2827 aNewSize.Height() -= ( _pImp->_a6Size.Height() / 2 );
2828 _pPrevWin->SetOutputSizePixel( aNewSize );
2829 _pPrevBmp->SetOutputSizePixel( aNewSize );
2830 _pPrevBmp->Invalidate();
2833 if ( _pFileNotifier )
2834 _pFileNotifier->notify( DIALOG_SIZE_CHANGED, 0 );
2837 //*****************************************************************************
2839 //-----------------------------------------------------------------------------
2840 Control* SvtFileDialog::getControl( sal_Int16 _nControlId, sal_Bool _bLabelControl ) const
2842 Control* pReturn = NULL;
2844 switch ( _nControlId )
2846 case CONTROL_FILEVIEW:
2847 pReturn = _bLabelControl ? NULL : static_cast< Control* >( _pFileView );
2848 break;
2850 case EDIT_FILEURL:
2851 pReturn = _bLabelControl
2852 ? static_cast< Control* >( _pImp->_pFtFileName )
2853 : static_cast< Control* >( _pImp->_pEdFileName );
2854 break;
2856 case EDIT_FILEURL_LABEL:
2857 pReturn = static_cast< Control* >( _pImp->_pFtFileName );
2858 break;
2860 case CHECKBOX_AUTOEXTENSION:
2861 pReturn = _pImp->_pCbAutoExtension;
2862 break;
2864 case CHECKBOX_PASSWORD:
2865 pReturn = _pImp->_pCbPassword;
2866 break;
2868 case CHECKBOX_FILTEROPTIONS:
2869 pReturn = _pImp->_pCbOptions;
2870 break;
2872 case CHECKBOX_READONLY:
2873 pReturn = _pCbReadOnly;
2874 break;
2876 case CHECKBOX_LINK:
2877 pReturn = _pCbLinkBox;
2878 break;
2880 case CHECKBOX_PREVIEW:
2881 pReturn = _pCbPreviewBox;
2882 break;
2884 case CHECKBOX_SELECTION:
2885 pReturn = _pCbSelection;
2886 break;
2888 case LISTBOX_FILTER:
2889 pReturn = _bLabelControl ? _pImp->_pFtFileType : _pImp->GetFilterListControl();
2890 break;
2892 case LISTBOX_FILTER_LABEL:
2893 pReturn = _pImp->_pFtFileType;
2894 break;
2896 case FIXEDTEXT_CURRENTFOLDER:
2897 pReturn = _pImp->_pFtCurrentPath;
2898 break;
2900 case LISTBOX_VERSION:
2901 pReturn = _bLabelControl
2902 ? static_cast< Control* >( _pImp->_pFtFileVersion )
2903 : static_cast< Control* >( _pImp->_pLbFileVersion );
2904 break;
2906 case LISTBOX_TEMPLATE:
2907 pReturn = _bLabelControl
2908 ? static_cast< Control* >( _pImp->_pFtTemplates )
2909 : static_cast< Control* >( _pImp->_pLbTemplates );
2910 break;
2912 case LISTBOX_IMAGE_TEMPLATE:
2913 pReturn = _bLabelControl
2914 ? static_cast< Control* >( _pImp->_pFtImageTemplates )
2915 : static_cast< Control* >( _pImp->_pLbImageTemplates );
2916 break;
2918 case LISTBOX_VERSION_LABEL:
2919 pReturn = _pImp->_pFtFileVersion;
2920 break;
2922 case LISTBOX_TEMPLATE_LABEL:
2923 pReturn = _pImp->_pFtTemplates;
2924 break;
2926 case LISTBOX_IMAGE_TEMPLATE_LABEL:
2927 pReturn = _pImp->_pFtImageTemplates;
2928 break;
2930 case PUSHBUTTON_OK:
2931 pReturn = _pImp->_pBtnFileOpen;
2932 break;
2934 case PUSHBUTTON_CANCEL:
2935 pReturn = _pImp->_pBtnCancel;
2936 break;
2938 case PUSHBUTTON_PLAY:
2939 pReturn = _pPbPlay;
2940 break;
2942 case PUSHBUTTON_HELP:
2943 pReturn = _pImp->_pBtnHelp;
2944 break;
2946 case TOOLBOXBUTOON_DEFAULT_LOCATION:
2947 pReturn = _pImp->_pBtnStandard;
2948 break;
2950 case TOOLBOXBUTOON_LEVEL_UP:
2951 pReturn = _pImp->_pBtnUp;
2952 break;
2954 case TOOLBOXBUTOON_NEW_FOLDER:
2955 pReturn = _pImp->_pBtnNewFolder;
2956 break;
2958 case LISTBOX_FILTER_SELECTOR:
2959 // only exists on SalGtkFilePicker
2960 break;
2962 default:
2963 DBG_ERRORFILE( "SvtFileDialog::getControl: invalid id!" );
2965 return pReturn;
2968 // -----------------------------------------------------------------------
2969 void SvtFileDialog::enableControl( sal_Int16 _nControlId, sal_Bool _bEnable )
2971 Control* pControl = getControl( _nControlId, sal_False );
2972 if ( pControl )
2973 EnableControl( pControl, _bEnable );
2974 Control* pLabel = getControl( _nControlId, sal_True );
2975 if ( pLabel )
2976 EnableControl( pLabel, _bEnable );
2979 // -----------------------------------------------------------------------
2980 void SvtFileDialog::AddControls_Impl( )
2982 // create the "insert as link" checkbox, if needed
2983 if ( _nExtraBits & SFX_EXTRA_INSERTASLINK )
2985 _pCbLinkBox = new CheckBox( this );
2986 _pCbLinkBox ->SetText( SvtResId( STR_SVT_FILEPICKER_INSERT_AS_LINK ) );
2987 _pCbLinkBox ->SetHelpId( HID_FILEDLG_LINK_CB );
2988 AddControl( _pCbLinkBox );
2989 ReleaseOwnerShip( _pCbLinkBox );
2990 _pCbLinkBox->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
2993 // create the "show preview" checkbox ( and the preview window, too ), if needed
2994 if ( _nExtraBits & SFX_EXTRA_SHOWPREVIEW )
2996 _pImp->_aIniKey = IMPGRF_CONFIGNAME;
2997 // because the "<All Formats> (*.bmp,*...)" entry is to wide,
2998 // we need to disable the auto width feature of the filter box
2999 _pImp->DisableFilterBoxAutoWidth();
3001 // "Vorschau"
3002 _pCbPreviewBox = new CheckBox( this );
3003 _pCbPreviewBox->SetText( SvtResId( STR_SVT_FILEPICKER_SHOW_PREVIEW ) );
3004 _pCbPreviewBox->SetHelpId( HID_FILEDLG_PREVIEW_CB );
3005 AddControl( _pCbPreviewBox );
3006 ReleaseOwnerShip( _pCbPreviewBox );
3007 _pCbPreviewBox->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
3009 // Preview-Fenster erst hier erzeugen
3010 _pPrevWin = new Window( this, WinBits( WB_BORDER ) );
3011 AddControl( _pPrevWin );
3012 ReleaseOwnerShip( _pPrevWin );
3013 _pPrevWin->Hide();
3015 _pPrevBmp = new FixedBitmap( this, WinBits( WB_BORDER ) );
3016 _pPrevBmp->SetBackground( Wallpaper( Color( COL_WHITE ) ) );
3017 _pPrevBmp->Show();
3020 if ( _nExtraBits & SFX_EXTRA_AUTOEXTENSION )
3022 _pImp->_pCbAutoExtension = new CheckBox( this, SvtResId( CB_AUTO_EXTENSION ) );
3023 _pImp->_pCbAutoExtension->SetText( SvtResId( STR_SVT_FILEPICKER_AUTO_EXTENSION ) );
3024 _pImp->_pCbAutoExtension->Check( TRUE );
3025 AddControl( _pImp->_pCbAutoExtension );
3026 ReleaseOwnerShip( _pImp->_pCbAutoExtension );
3027 _pImp->_pCbAutoExtension->SetClickHdl( LINK( this, SvtFileDialog, AutoExtensionHdl_Impl ) );
3030 if ( _nExtraBits & SFX_EXTRA_FILTEROPTIONS )
3032 _pImp->_pCbOptions = new CheckBox( this, SvtResId( CB_OPTIONS ) );
3033 _pImp->_pCbOptions->SetText( SvtResId( STR_SVT_FILEPICKER_FILTER_OPTIONS ) );
3034 AddControl( _pImp->_pCbOptions );
3035 ReleaseOwnerShip( _pImp->_pCbOptions );
3036 _pImp->_pCbOptions->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
3039 if ( _nExtraBits & SFX_EXTRA_SELECTION )
3041 _pCbSelection = new CheckBox( this, SvtResId( CB_OPTIONS ) );
3042 _pCbSelection->SetText( SvtResId( STR_SVT_FILEPICKER_SELECTION ) );
3043 AddControl( _pCbSelection );
3044 ReleaseOwnerShip( _pCbSelection );
3045 _pCbSelection->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
3048 if ( _nExtraBits & SFX_EXTRA_PLAYBUTTON )
3050 _pPbPlay = new PushButton( this );
3051 _pPbPlay->SetText( SvtResId( STR_SVT_FILEPICKER_PLAY ) );
3052 _pPbPlay->SetHelpId( HID_FILESAVE_DOPLAY );
3053 AddControl( _pPbPlay );
3054 ReleaseOwnerShip( _pPbPlay );
3055 _pPbPlay->SetClickHdl( LINK( this, SvtFileDialog, PlayButtonHdl_Impl ) );
3058 if ( _nExtraBits & SFX_EXTRA_SHOWVERSIONS )
3060 _pImp->_pFtFileVersion = new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
3061 _pImp->_pFtFileVersion->SetText( SvtResId( STR_SVT_FILEPICKER_VERSION ) );
3063 _pImp->_pLbFileVersion = new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
3064 _pImp->_pLbFileVersion->SetHelpId( HID_FILEOPEN_VERSION );
3066 else if ( _nExtraBits & SFX_EXTRA_TEMPLATES )
3068 _pImp->_pFtTemplates = new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
3069 _pImp->_pFtTemplates->SetText( SvtResId( STR_SVT_FILEPICKER_TEMPLATES ) );
3071 _pImp->_pLbTemplates = new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
3072 _pImp->_pLbTemplates->SetHelpId( HID_FILEOPEN_VERSION );
3073 // This is strange. During the re-factoring during 96930, I discovered that this help id
3074 // is set in the "Templates mode". This was hidden in the previous implementation.
3075 // Shouldn't this be a more meaningfull help id.
3076 // 96930 - 15.08.2002 - fs@openoffice.org
3078 else if ( _nExtraBits & SFX_EXTRA_IMAGE_TEMPLATE )
3080 _pImp->_pFtImageTemplates = new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
3081 _pImp->_pFtImageTemplates->SetText( SvtResId( STR_SVT_FILEPICKER_IMAGE_TEMPLATE ) );
3083 _pImp->_pLbImageTemplates = new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
3084 _pImp->_pLbImageTemplates->SetHelpId( HID_FILEOPEN_IMAGE_TEMPLATE );
3088 // -----------------------------------------------------------------------
3089 sal_Int32 SvtFileDialog::getTargetColorDepth()
3091 if ( _pPrevBmp )
3092 return _pPrevBmp->GetBitCount();
3093 else
3094 return 0;
3097 // -----------------------------------------------------------------------
3098 sal_Int32 SvtFileDialog::getAvailableWidth()
3100 if ( _pPrevBmp )
3101 return _pPrevBmp->GetOutputSizePixel().Width();
3102 else
3103 return 0;
3106 // -----------------------------------------------------------------------
3107 sal_Int32 SvtFileDialog::getAvailableHeight()
3109 if ( _pPrevBmp )
3110 return _pPrevBmp->GetOutputSizePixel().Height();
3111 else
3112 return 0;
3115 // -----------------------------------------------------------------------
3116 void SvtFileDialog::setImage( sal_Int16 /*aImageFormat*/, const Any& rImage )
3118 if ( ! _pPrevBmp || ! _pPrevBmp->IsVisible() )
3119 return;
3121 Sequence < sal_Int8 > aBmpSequence;
3123 if ( rImage >>= aBmpSequence )
3125 Bitmap aBmp;
3126 SvMemoryStream aData( aBmpSequence.getArray(),
3127 aBmpSequence.getLength(),
3128 STREAM_READ );
3129 aData >> aBmp;
3131 _pPrevBmp->SetBitmap( aBmp );
3133 else
3135 Bitmap aEmpty;
3136 _pPrevBmp->SetBitmap( aEmpty );
3140 // -----------------------------------------------------------------------
3141 sal_Bool SvtFileDialog::setShowState( sal_Bool /*bShowState*/ )
3143 // #97633 for the system filedialog it's
3144 // usefull to make the preview switchable
3145 // because the preview occupies
3146 // half of the size of the file listbox
3147 // which is not the case here,
3148 // so we (TRA/FS) decided not to make
3149 // the preview window switchable because
3150 // else we would have to change the layout
3151 // of the file dialog dynamically
3152 // support for set/getShowState is opionally
3153 // see com::sun::star::ui::dialogs::XFilePreview
3155 if ( _pPrevBmp )
3157 _pPrevBmp->Show( bShowState );
3158 return sal_True;
3160 else
3161 return sal_False;
3164 return sal_False;
3167 // -----------------------------------------------------------------------
3168 String SvtFileDialog::getCurrentFileText( ) const
3170 String sReturn;
3171 if ( _pImp && _pImp->_pEdFileName )
3172 sReturn = _pImp->_pEdFileName->GetText();
3173 return sReturn;
3176 // -----------------------------------------------------------------------
3177 void SvtFileDialog::setCurrentFileText( const String& _rText, bool _bSelectAll )
3179 if ( _pImp && _pImp->_pEdFileName )
3181 _pImp->_pEdFileName->SetText( _rText );
3182 if ( _bSelectAll )
3183 _pImp->_pEdFileName->SetSelection( Selection( 0, _rText.Len() ) );
3187 // -----------------------------------------------------------------------
3188 sal_Bool SvtFileDialog::isAutoExtensionEnabled()
3190 return _pImp->_pCbAutoExtension && _pImp->_pCbAutoExtension->IsChecked();
3193 // -----------------------------------------------------------------------
3194 sal_Bool SvtFileDialog::getShowState()
3196 if ( _pPrevBmp )
3197 return _pPrevBmp->IsVisible();
3198 else
3199 return sal_False;
3202 // -----------------------------------------------------------------------
3203 void SvtFileDialog::ReleaseOwnerShip( Window* pUserControl )
3206 [Beschreibung]
3207 Die Methode sorgt dafuer das das spezifizierte Element nicht mehr im Besitz
3208 der Instanz ist.
3212 ControlChain_Impl* pElement = _pUserControls;
3213 while ( pElement )
3215 if ( pElement->_pControl == pUserControl )
3217 pElement->_bHasOwnerShip = FALSE;
3218 break;
3220 pElement = pElement->_pNext;
3224 //***************************************************************************
3226 BOOL SvtFileDialog::AddControl( Window* pControl, BOOL bNewLine )
3228 // control already exists
3229 ControlChain_Impl* pElement = _pUserControls;
3230 while ( pElement )
3232 if ( pElement->_pControl == pControl )
3233 return FALSE;
3234 pElement = pElement->_pNext;
3237 // Check if controls have already been added.
3238 Size aNewControlSize( pControl->GetOutputSizePixel() );
3239 Size aDlgSize( GetOutputSizePixel() );
3240 WindowType nType = pControl->GetType();
3241 if ( !aNewControlSize.Height() )
3243 // Detect a size.
3244 Size aSize( 0, 10 );
3245 if ( nType == WINDOW_PUSHBUTTON )
3247 Size aDefSiz = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
3248 long nTextWidth = pControl->GetTextWidth( pControl->GetText() );
3249 aSize.Width() = nTextWidth + WIDTH_ADDITION;
3251 // PushButton: Mindestbreite 50 logische Einheiten,
3252 // H"ohe immer 14 logische Einheiten
3253 if ( aDefSiz.Width() > aSize.Width() )
3254 aSize.Width() = aDefSiz.Width();
3255 aSize.Height() = aDefSiz.Height();
3256 aNewControlSize = aSize;
3258 else
3259 aNewControlSize = LogicToPixel( aSize, MAP_APPFONT );
3260 if ( nType != WINDOW_PUSHBUTTON )
3261 aNewControlSize.Width() = pControl->GetTextWidth( pControl->GetText() ) + WIDTH_ADDITION;
3262 if ( nType == WINDOW_CHECKBOX )
3263 aNewControlSize.Width() += WIDTH_ADDITION;
3264 if ( nType == WINDOW_WINDOW )
3266 aNewControlSize.Height() = GetOutputSizePixel().Height() - 18;
3267 aNewControlSize.Width() = 200;
3268 aDlgSize.Width() += 210;
3269 SetOutputSizePixel( aDlgSize );
3271 pControl->SetOutputSizePixel( aNewControlSize );
3273 Point aNewControlPos;
3274 Size* pNewDlgSize = NULL;
3275 BOOL bNewRow = bNewLine;
3276 FASTBOOL bFirstNewRow = FALSE;
3278 if ( nType == WINDOW_WINDOW )
3280 aNewControlPos.X() = aDlgSize.Width() - 210;
3281 aNewControlPos.Y() = 8;
3283 else if ( _pUserControls )
3285 Point aNewControlRange( _pUserControls->_pControl->GetPosPixel() );
3286 long nPrevControlHeight = _pUserControls->_pControl->GetSizePixel().Height();
3287 aNewControlRange +=
3288 Point( _pUserControls->_pControl->GetOutputSizePixel().Width(), 0 );
3289 aNewControlPos = aNewControlRange;
3290 if ( nPrevControlHeight > aNewControlSize.Height() )
3292 long nY = nPrevControlHeight;
3293 nY -= aNewControlSize.Height();
3294 nY /= 2;
3295 aNewControlPos.Y() += nY;
3297 aNewControlPos += LogicToPixel( Point( 3, 0 ), MAP_APPFONT );
3298 aNewControlRange += LogicToPixel( Point( 9, 0 ), MAP_APPFONT );
3299 aNewControlRange += Point( aNewControlSize.Width(), 0 );
3301 // Check if a new row has to be created.
3302 if ( aNewControlRange.X() > aDlgSize.Width() )
3303 bNewRow = TRUE;
3305 else
3307 // Create a new row if there was no usercontrol before.
3308 bNewRow = TRUE;
3309 bFirstNewRow = TRUE;
3312 // Check if a new row has to be created.
3313 Size aBorderSize = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
3314 long nLeftBorder = aBorderSize.Width();
3315 long nLowerBorder = aBorderSize.Height();
3316 if ( bNewRow )
3318 // Set control at the beginning of a new line.
3319 long nSmallBorderHeight = nLowerBorder / 2;
3320 aNewControlPos = Point( nLeftBorder, 0 );
3321 aNewControlPos += Point( 0, aDlgSize.Height() );
3322 aNewControlPos.Y() -= nSmallBorderHeight;
3323 // Set new size.
3324 pNewDlgSize = new Size( aDlgSize );
3325 pNewDlgSize->Height() -= nSmallBorderHeight;
3326 pNewDlgSize->Height() += aNewControlSize.Height();
3327 pNewDlgSize->Height() += nLowerBorder;
3329 else
3331 // Check if the window has to be resized.
3332 Size aNewControlRange( 0, aNewControlPos.Y() );
3333 aNewControlRange.Height() += aNewControlSize.Height();
3334 aNewControlRange.Height() += nLowerBorder;
3335 if ( aNewControlRange.Height() > aDlgSize.Height() )
3336 pNewDlgSize = new Size( aDlgSize.Width(), aNewControlRange.Height() );
3339 // Update view.
3340 if ( pNewDlgSize )
3342 SetOutputSizePixel( *pNewDlgSize );
3343 delete pNewDlgSize;
3345 pControl->SetPosPixel( aNewControlPos );
3346 pControl->Show();
3347 _pUserControls = new ControlChain_Impl( pControl, _pUserControls );
3349 return TRUE;
3352 sal_Bool SvtFileDialog::ContentHasParentFolder( const rtl::OUString& rURL )
3354 m_aContent.bindTo( rURL );
3356 if ( m_aContent.isInvalid() )
3357 return sal_False;
3359 return m_aContent.hasParentFolder( ) && m_aContent.isValid();
3362 sal_Bool SvtFileDialog::ContentCanMakeFolder( const rtl::OUString& rURL )
3364 m_aContent.bindTo( rURL );
3366 if ( m_aContent.isInvalid() )
3367 return sal_False;
3369 return m_aContent.canCreateFolder( ) && m_aContent.isValid();
3372 sal_Bool SvtFileDialog::ContentGetTitle( const rtl::OUString& rURL, String& rTitle )
3374 m_aContent.bindTo( rURL );
3376 if ( m_aContent.isInvalid() )
3377 return sal_False;
3379 ::rtl::OUString sTitle;
3380 m_aContent.getTitle( sTitle );
3381 rTitle = sTitle;
3383 return m_aContent.isValid();
3386 void SvtFileDialog::appendDefaultExtension(String& _rFileName,
3387 const String& _rFilterDefaultExtension,
3388 const String& _rFilterExtensions)
3390 String aTemp(_rFileName);
3391 aTemp.ToLowerAscii();
3392 String aType(_rFilterExtensions);
3393 aType.ToLowerAscii();
3395 if ( ! aType.EqualsAscii(FILEDIALOG_FILTER_ALL) )
3397 USHORT nWildCard = aType.GetTokenCount( FILEDIALOG_DEF_EXTSEP );
3398 USHORT nIndex, nPos = 0;
3400 for ( nIndex = 0; nIndex < nWildCard; nIndex++ )
3402 String aExt(aType.GetToken( 0, FILEDIALOG_DEF_EXTSEP, nPos ));
3403 // take care of a leading *
3404 USHORT nExtOffset = (aExt.GetBuffer()[0] == '*' ? 1 : 0);
3405 sal_Unicode* pExt = aExt.GetBufferAccess() + nExtOffset;
3406 xub_StrLen nExtLen = aExt.Len() - nExtOffset;
3407 xub_StrLen nOffset = aTemp.Len() - nExtLen;
3408 // minimize search by starting at last possible index
3409 if ( aTemp.Search(pExt, nOffset) == nOffset )
3410 break;
3413 if ( nIndex >= nWildCard )
3415 _rFileName += '.';
3416 _rFileName += _rFilterDefaultExtension;
3421 // -----------------------------------------------------------------------
3423 // QueryFolderNameDialog -------------------------------------------------------
3425 namespace svtools {
3427 QueryFolderNameDialog::QueryFolderNameDialog
3429 Window* _pParent,
3430 const String& rTitle,
3431 const String& rDefaultText,
3432 String* pGroupName
3434 ModalDialog( _pParent, SvtResId( DLG_SVT_QUERYFOLDERNAME ) ),
3436 aNameText ( this, SvtResId( FT_SVT_QUERYFOLDERNAME_DLG_NAME ) ),
3437 aNameEdit ( this, SvtResId( ED_SVT_QUERYFOLDERNAME_DLG_NAME ) ),
3438 aNameLine ( this, SvtResId( FL_SVT_QUERYFOLDERNAME_DLG_NAME ) ),
3439 aOKBtn ( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_OK ) ),
3440 aCancelBtn ( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_CANCEL ) )
3442 FreeResource();
3443 SetText( rTitle );
3444 aNameEdit.SetText( rDefaultText );
3445 aNameEdit.SetSelection( Selection( 0, rDefaultText.Len() ) );
3446 aOKBtn.SetClickHdl( LINK( this, QueryFolderNameDialog, OKHdl ) );
3447 aNameEdit.SetModifyHdl( LINK( this, QueryFolderNameDialog, NameHdl ) );
3449 if ( pGroupName )
3450 aNameLine.SetText( *pGroupName );
3453 // -----------------------------------------------------------------------
3454 IMPL_LINK( QueryFolderNameDialog, OKHdl, Button *, EMPTYARG )
3456 // trim the strings
3457 aNameEdit.SetText( aNameEdit.GetText().EraseLeadingChars().EraseTrailingChars() );
3458 EndDialog( RET_OK );
3459 return 1;
3462 // -----------------------------------------------------------------------
3463 IMPL_LINK( QueryFolderNameDialog, NameHdl, Edit *, EMPTYARG )
3465 // trim the strings
3466 String aName = aNameEdit.GetText();
3467 aName.EraseLeadingChars().EraseTrailingChars();
3468 if ( aName.Len() )
3470 if ( !aOKBtn.IsEnabled() )
3471 aOKBtn.Enable( TRUE );
3473 else
3475 if ( aOKBtn.IsEnabled() )
3476 aOKBtn.Enable( FALSE );
3479 return 0;