xref: /aoo41x/main/fpicker/source/office/iodlg.cxx (revision b557fc96)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_fpicker.hxx"
26 
27 // includes --------------------------------------------------------------
28 
29 #include "iodlg.hxx"
30 #include <tools/stream.hxx>
31 #include <tools/urlobj.hxx>
32 #include <vcl/fixed.hxx>
33 #include <vcl/lstbox.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/timer.hxx>
37 #include <unotools/ucbhelper.hxx>
38 #include <ucbhelper/contentbroker.hxx>
39 #include "svtools/ehdl.hxx"
40 #include "svl/urihelper.hxx"
41 #include "unotools/pathoptions.hxx"
42 #include "unotools/viewoptions.hxx"
43 #include "svtools/fileview.hxx"
44 #include "unotools/inetoptions.hxx"
45 #include "svtools/sfxecode.hxx"
46 #include "svl/svarray.hxx"
47 #include "svtools/svtabbx.hxx"
48 
49 #define _SVSTDARR_USHORTS
50 #define _SVSTDARR_STRINGSDTOR
51 #include "svl/svstdarr.hxx"
52 #include <toolkit/helper/vclunohelper.hxx>
53 #include <unotools/localfilehelper.hxx>
54 
55 #ifndef _SVTOOLS_HRC
56 #include "svtools/svtools.hrc"
57 #endif
58 #ifndef _SVT_HELPID_HRC
59 #include "svtools/helpid.hrc"
60 #endif
61 #ifndef _SVTOOLS_IODLGIMPL_HRC
62 #include "iodlg.hrc"
63 #endif
64 #include "rtl/instance.hxx"
65 #include "asyncfilepicker.hxx"
66 #include "iodlgimp.hxx"
67 #include "svtools/inettbc.hxx"
68 #include "unotools/syslocale.hxx"
69 #include "svtools/QueryFolderName.hxx"
70 #ifndef  _RTL_USTRING_HXX
71 #include <rtl/ustring.hxx>
72 #endif
73 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
74 #include <com/sun/star/ucb/XContentProviderManager.hpp>
75 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
76 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
77 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
78 #include <com/sun/star/beans/PropertyValue.hpp>
79 #include <com/sun/star/sdbc/XResultSet.hpp>
80 #include <com/sun/star/sdbc/XRow.hpp>
81 #include <com/sun/star/util/URL.hpp>
82 #include <com/sun/star/uno/Exception.hpp>
83 #include <com/sun/star/uno/Reference.hxx>
84 #include <com/sun/star/util/XURLTransformer.hpp>
85 #include <com/sun/star/uno/RuntimeException.hpp>
86 #include <com/sun/star/beans/XPropertySet.hpp>
87 
88 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
89 #include <comphelper/processfactory.hxx>
90 #endif
91 #include <osl/file.h>
92 #include <vcl/waitobj.hxx>
93 
94 // #97148# ------------------------------------
95 #include <com/sun/star/task/XInteractionHandler.hpp>
96 #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
97 #include "fpinteraction.hxx"
98 #include <osl/process.h>
99 #include <comphelper/interaction.hxx>
100 
101 #include <algorithm>
102 #include <functional>
103 
104 //#define AUTOSELECT_USERFILTER
105 	// define this for the experimental feature of user-filter auto selection
106 	// means if the user enters e.g. *.doc<enter>, and there is a filter which is responsible for *.doc files (only),
107 	// then this filter is selected automatically
108 
109 using namespace ::com::sun::star::beans;
110 using namespace ::com::sun::star::frame;
111 using namespace ::com::sun::star::ui::dialogs;
112 using namespace ::com::sun::star::uno;
113 using namespace ::com::sun::star::lang;
114 using namespace ::com::sun::star::ucb;
115 using namespace ::com::sun::star::container;
116 using namespace ::com::sun::star::task;
117 using namespace ::com::sun::star::sdbc;
118 using namespace ::utl;
119 using namespace ::svt;
120 
121 using namespace ExtendedFilePickerElementIds;
122 using namespace CommonFilePickerElementIds;
123 using namespace InternalFilePickerElementIds;
124 
125 #define IODLG_CONFIGNAME		String(RTL_CONSTASCII_USTRINGPARAM("FileDialog"))
126 #define IMPGRF_CONFIGNAME		String(RTL_CONSTASCII_USTRINGPARAM("ImportGraphicDialog"))
127 
128 #define GET_DECODED_NAME(aObj) \
129 	aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET )
130 
131 // Zeit die beim Traveln in der Filterbox gewartet wird,
132 // bis in der Browsebox gefiltert wird ( in ms ).
133 #define TRAVELFILTER_TIMEOUT	750
134 
135 #define WIDTH_ADDITION	15
136 
137 // functions -------------------------------------------------------------
138 
139 namespace
140 {
141 
142 	//-----------------------------------------------------------------------------
143 	String getMostCurrentFilter( SvtExpFileDlg_Impl* pImpl )
144 	{
145 		DBG_ASSERT( pImpl, "invalid impl pointer" );
146 		const SvtFileDialogFilter_Impl* pFilter = pImpl->_pUserFilter;
147 
148 		if ( !pFilter )
149 			pFilter = pImpl->GetCurFilter();
150 
151 		// Filtern.
152 		if ( !pFilter )
153 			return String();
154 
155 		return pFilter->GetType();
156 	}
157 
158 	//-----------------------------------------------------------------------------
159 	sal_Bool restoreCurrentFilter( SvtExpFileDlg_Impl* _pImpl )
160 	{
161 		DBG_ASSERT( _pImpl->GetCurFilter(), "restoreCurrentFilter: no current filter!" );
162 		DBG_ASSERT( _pImpl->GetCurFilterDisplayName().Len(), "restoreCurrentFilter: no current filter (no display name)!" );
163 
164 		_pImpl->SelectFilterListEntry( _pImpl->GetCurFilterDisplayName() );
165 
166 #ifdef DBG_UTIL
167 		String sSelectedDisplayName;
168 		DBG_ASSERT(	( _pImpl->GetSelectedFilterEntry( sSelectedDisplayName ) == _pImpl->GetCurFilter() )
169 				&&	( sSelectedDisplayName == _pImpl->GetCurFilterDisplayName() ),
170 			"restoreCurrentFilter: inconsistence!" );
171 #endif
172 		return _pImpl->m_bNeedDelayedFilterExecute;
173 	}
174 
175 	//-----------------------------------------------------------------------------
176     String GetFsysExtension_Impl( const String& rFile, const String& rLastFilterExt )
177 	{
178         xub_StrLen nDotPos = rFile.SearchBackward( '.' );
179         if ( nDotPos != STRING_NOTFOUND )
180         {
181             if ( rLastFilterExt.Len() )
182             {
183                 if ( rFile.Copy( nDotPos + 1 ).EqualsIgnoreCaseAscii( rLastFilterExt ) )
184                     return String( rLastFilterExt );
185             }
186             else
187                 return String( rFile.Copy( nDotPos ) );
188         }
189 		return String();
190 	}
191 
192 	//-----------------------------------------------------------------------------
193 	void SetFsysExtension_Impl( String& rFile, const String& rExtension )
194 	{
195 		const sal_Unicode* p0 = rFile.GetBuffer();
196 		const sal_Unicode* p1 = p0 + rFile.Len() - 1;
197 		while ( p1 >= p0 && *p1 != sal_Unicode( '.' ) )
198 			p1--;
199 		if ( p1 >= p0 )
200 			// remove old extension
201 			rFile.Erase(
202                 sal::static_int_cast< xub_StrLen >(
203                     p1 - p0 + 1 - ( rExtension.Len() > 0 ? 0 : 1 ) ) );
204 		else if ( rExtension.Len() )
205 			// no old extension
206 			rFile += sal_Unicode( '.' );
207 		rFile += rExtension;
208 	}
209 
210 	//-----------------------------------------------------------------------------
211 	// move the control with the given offset
212 	void lcl_MoveControl( Control* _pControl, sal_Int32 _nDeltaX, sal_Int32 _nDeltaY, sal_Int32* _pMaxY = NULL )
213 	{
214 		if ( _pControl )
215 		{
216 			Point aNewPos = _pControl->GetPosPixel();
217 
218 			// adjust the vertical position
219 			aNewPos.Y() += _nDeltaY;
220 			if ( _pMaxY && ( aNewPos.Y() > *_pMaxY ) )
221 				*_pMaxY = aNewPos.Y();
222 
223 			// adjust the horizontal position
224 			aNewPos.X() += _nDeltaX;
225 
226 			_pControl->SetPosPixel( aNewPos );
227 		}
228 	}
229 
230     //-------------------------------------------------------------------------
231     void lcl_autoUpdateFileExtension( SvtFileDialog* _pDialog, const String& _rLastFilterExt )
232 	{
233 		// if auto extension is enabled ....
234 		if ( _pDialog->isAutoExtensionEnabled() )
235 		{
236 			// automatically switch to the extension of the (maybe just newly selected) extension
237 			String aNewFile = _pDialog->getCurrentFileText( );
238             String aExt = GetFsysExtension_Impl( aNewFile, _rLastFilterExt );
239 
240 			// but only if there already is an extension
241 			if ( aExt.Len() )
242 			{
243 				// check if it is a real file extension, and not only the "post-dot" part in
244 				// a directory name
245 				// 28.03.2002 - 98337 - fs@openoffice.org
246 				sal_Bool bRealExtensions = sal_True;
247 				if ( STRING_NOTFOUND != aExt.Search( '/' ) )
248 					bRealExtensions = sal_False;
249 				else if ( STRING_NOTFOUND != aExt.Search( '\\' ) )
250 					bRealExtensions = sal_False;
251 				else
252 				{
253 					// no easy way to tell, because the part containing the dot already is the last
254 					// segment of the complete file name
255 					// So we have to check if the file name denotes a folder or a file.
256 					// For performance reasons, we do this for file urls only
257 					INetURLObject aURL( aNewFile );
258 					if ( INET_PROT_NOT_VALID == aURL.GetProtocol() )
259 					{
260 						String sURL;
261 						if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aNewFile, sURL ) )
262 							aURL = INetURLObject( sURL );
263 					}
264 					if ( INET_PROT_FILE == aURL.GetProtocol() )
265 					{
266 						// #97148# & #102204# -----
267 						try
268 						{
269 							bRealExtensions = !_pDialog->ContentIsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
270 						}
271 						catch( ::com::sun::star::uno::Exception& )
272 						{
273 							DBG_WARNING( "Exception in lcl_autoUpdateFileExtension" );
274 						}
275 					}
276 				}
277 
278 				if ( bRealExtensions )
279 				{
280 					SetFsysExtension_Impl( aNewFile, _pDialog->GetDefaultExt() );
281 					_pDialog->setCurrentFileText( aNewFile );
282 				}
283 			}
284 		}
285 	}
286 
287 	//-------------------------------------------------------------------------
288 	sal_Bool lcl_getHomeDirectory( const String& _rForURL, String& /* [out] */ _rHomeDir )
289 	{
290 		_rHomeDir.Erase();
291 
292 		// now ask the content broker for a provider for this scheme
293         //=================================================================
294 		try
295 		{
296 			// get the content provider manager
297 			::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
298 			Reference< XContentProviderManager > xProviderManager;
299 			if ( pBroker )
300 				xProviderManager = pBroker->getContentProviderManagerInterface();
301 
302             //=================================================================
303 			// get the provider for the current scheme
304 			Reference< XContentProvider > xProvider;
305 			if ( xProviderManager.is() )
306 				xProvider = xProviderManager->queryContentProvider( _rForURL );
307 
308 			DBG_ASSERT( xProvider.is(), "lcl_getHomeDirectory: could not find a (valid) content provider for the current URL!" );
309 			Reference< XPropertySet > xProviderProps( xProvider, UNO_QUERY );
310 			if ( xProviderProps.is() )
311 			{
312 				Reference< XPropertySetInfo > xPropInfo = xProviderProps->getPropertySetInfo();
313 				const ::rtl::OUString sHomeDirPropertyName( RTL_CONSTASCII_USTRINGPARAM( "HomeDirectory" ) );
314 				if ( !xPropInfo.is() || xPropInfo->hasPropertyByName( sHomeDirPropertyName ) )
315 				{
316 					::rtl::OUString sHomeDirectory;
317 					xProviderProps->getPropertyValue( sHomeDirPropertyName ) >>= sHomeDirectory;
318 					_rHomeDir = sHomeDirectory;
319 				}
320 			}
321 		}
322 		catch( const Exception& )
323 		{
324 			DBG_ERROR( "lcl_getHomeDirectory: caught an exception!" );
325 		}
326 		return 0 < _rHomeDir.Len();
327 	}
328 
329     //---------------------------------------------------------------------
330 	static String lcl_ensureFinalSlash( const String& _rDir )
331 	{
332 		INetURLObject aWorkPathObj( _rDir, INET_PROT_FILE );
333 		aWorkPathObj.setFinalSlash();
334 		return  aWorkPathObj.GetMainURL( INetURLObject::NO_DECODE );
335 	}
336 
337     //---------------------------------------------------------------------
338     void    convertStringListToUrls( const String& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash )
339     {
340         const sal_Unicode s_cSeparator =
341 #if defined(WNT) || defined(OS2)
342             ';'
343 #else
344             ':'
345 #endif
346             ;
347         xub_StrLen nTokens = _rColonSeparatedList.GetTokenCount( s_cSeparator );
348         _rTokens.resize( 0 ); _rTokens.reserve( nTokens );
349         for ( xub_StrLen i=0; i<nTokens; ++i )
350         {
351             // the current token in the list
352             String sCurrentToken = _rColonSeparatedList.GetToken( i, s_cSeparator );
353             if ( !sCurrentToken.Len() )
354                 continue;
355 
356             INetURLObject aCurrentURL;
357 
358             String sURL;
359             if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) )
360                 aCurrentURL = INetURLObject( sURL );
361             else
362             {
363                 // smart URL parsing, assuming FILE protocol
364                 aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE );
365             }
366 
367             if ( _bFinalSlash )
368                 aCurrentURL.setFinalSlash( );
369             else
370                 aCurrentURL.removeFinalSlash( );
371             _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) );
372         }
373     }
374 
375     //---------------------------------------------------------------------
376     struct RemoveFinalSlash : public ::std::unary_function< String, void >
377     {
378         void operator()( String& _rURL )
379         {
380             INetURLObject aURL( _rURL );
381 #if defined(WNT) || defined(OS2)
382             if ( aURL.getSegmentCount() > 1 )
383 #endif
384                 aURL.removeFinalSlash( );
385             _rURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
386         }
387     };
388 
389     // -----------------------------------------------------------------------
390     /** retrieves the value of an environment variable
391         @return <TRUE/> if and only if the retrieved string value is not empty
392     */
393     bool getEnvironmentValue( const sal_Char* _pAsciiEnvName, ::rtl::OUString& _rValue )
394     {
395         _rValue = ::rtl::OUString();
396         ::rtl::OUString sEnvName = ::rtl::OUString::createFromAscii( _pAsciiEnvName );
397         osl_getEnvironment( sEnvName.pData, &_rValue.pData );
398         return _rValue.getLength() != 0;
399     }
400 }
401 
402 //***************************************************************************
403 // ControlChain_Impl
404 //***************************************************************************
405 
406 struct ControlChain_Impl
407 {
408 	Window* 		   _pControl;
409 	ControlChain_Impl* _pNext;
410 	sal_Bool			   _bHasOwnerShip;
411 
412 	ControlChain_Impl( Window* pControl, ControlChain_Impl* pNext );
413 	~ControlChain_Impl();
414 };
415 
416 //***************************************************************************
417 
418 ControlChain_Impl::ControlChain_Impl
419 (
420 	Window* pControl,
421 	ControlChain_Impl* pNext
422 )
423 	: _pControl( pControl ),
424 	  _pNext( pNext ),
425 	  _bHasOwnerShip( sal_True )
426 {
427 }
428 
429 //***************************************************************************
430 
431 ControlChain_Impl::~ControlChain_Impl()
432 {
433 	if ( _bHasOwnerShip )
434 	{
435 		delete _pControl;
436 	}
437 	delete _pNext;
438 }
439 
440 //*****************************************************************************
441 // ResMgrHolder
442 //*****************************************************************************
443 namespace
444 {
445 	struct ResMgrHolder
446 	{
447 		ResMgr * operator ()()
448 		{
449 			return ResMgr::CreateResMgr (CREATEVERSIONRESMGR_NAME(fps_office));
450 		}
451 
452 		static ResMgr * getOrCreate()
453 		{
454 			return rtl_Instance<
455 				ResMgr, ResMgrHolder,
456 				osl::MutexGuard, osl::GetGlobalMutex >::create (
457 					ResMgrHolder(), osl::GetGlobalMutex());
458 		}
459 	};
460 
461 	struct SvtResId : public ResId
462 	{
463 		SvtResId (sal_uInt16 nId) : ResId (nId, *ResMgrHolder::getOrCreate()) {}
464 	};
465 }
466 
467 //*****************************************************************************
468 // SvtFileDialog
469 //*****************************************************************************
470 SvtFileDialog::SvtFileDialog
471 (
472 	Window* _pParent,
473 	WinBits nBits,
474 	WinBits nExtraBits
475 ) :
476 	ModalDialog( _pParent, SvtResId( DLG_SVT_EXPLORERFILE ) )
477 
478     ,_pUserControls( NULL )
479     ,_pCbReadOnly( NULL )
480 	,_pCbLinkBox( NULL)
481     ,_pCbPreviewBox( NULL )
482     ,_pCbSelection( NULL )
483     ,_pPbPlay( NULL )
484     ,_pPrevWin( NULL )
485     ,_pPrevBmp( NULL )
486     ,_pFileView( NULL )
487     ,_pFileNotifier( NULL )
488     ,_pImp( new SvtExpFileDlg_Impl( nBits ) )
489     ,_nExtraBits( nExtraBits )
490     ,_bIsInExecute( sal_False )
491     ,m_bInExecuteAsync( false )
492 	,m_bHasFilename( false )
493 {
494 	Init_Impl( nBits );
495 }
496 
497 //*****************************************************************************
498 
499 SvtFileDialog::SvtFileDialog ( Window* _pParent, WinBits nBits )
500     :ModalDialog( _pParent, SvtResId( DLG_SVT_EXPLORERFILE ) )
501     ,_pUserControls( NULL )
502     ,_pCbReadOnly( NULL )
503 	,_pCbLinkBox( NULL)
504     ,_pCbPreviewBox( NULL )
505     ,_pCbSelection( NULL )
506     ,_pPbPlay( NULL )
507     ,_pPrevWin( NULL )
508     ,_pPrevBmp( NULL )
509     ,_pFileView( NULL )
510     ,_pFileNotifier( NULL )
511     ,_pImp( new SvtExpFileDlg_Impl( nBits ) )
512     ,_nExtraBits( 0L )
513     ,_bIsInExecute( sal_False )
514 	,m_bHasFilename( false )
515 {
516 	Init_Impl( nBits );
517 }
518 
519 //*****************************************************************************
520 
521 SvtFileDialog::~SvtFileDialog()
522 {
523 	if ( _pImp->_aIniKey.Len() )
524 	{
525 		// save window state
526 		SvtViewOptions aDlgOpt( E_DIALOG, _pImp->_aIniKey );
527         aDlgOpt.SetWindowState( String( GetWindowState(), osl_getThreadTextEncoding() ) );
528 		String sUserData = _pFileView->GetConfigString();
529 		aDlgOpt.SetUserItem( ::rtl::OUString::createFromAscii( "UserData" ),
530 							 makeAny( ::rtl::OUString( sUserData ) ) );
531 	}
532 
533 	_pFileView->SetSelectHdl( Link() );
534 
535 	delete _pImp;
536 	delete _pFileView;
537 
538 	delete _pCbReadOnly;
539 	delete _pCbLinkBox;
540     delete _pCbPreviewBox;
541     delete _pCbSelection;
542     delete _pPbPlay;
543     delete _pPrevWin;
544     delete _pPrevBmp;
545 
546 	delete _pUserControls;
547 }
548 
549 //*****************************************************************************
550 
551 void SvtFileDialog::Init_Impl
552 (
553 	WinBits nStyle
554 )
555 {
556 	sal_Bool bIsHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
557 	m_aImages = ImageList( SvtResId( bIsHighContrast ? RID_FILEPICKER_IMAGES_HC : RID_FILEPICKER_IMAGES ) );
558 
559 	_pImp->_nStyle = nStyle;
560 	_pImp->_a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
561 	_pImp->_eMode = ( nStyle & WB_SAVEAS ) ? FILEDLG_MODE_SAVE : FILEDLG_MODE_OPEN;
562 	_pImp->_eDlgType = FILEDLG_TYPE_FILEDLG;
563 
564 	if ( ( nStyle & SFXWB_PATHDIALOG ) == SFXWB_PATHDIALOG )
565 		_pImp->_eDlgType = FILEDLG_TYPE_PATHDLG;
566 
567 	// Set the directory for the "back to the default dir" button
568 	INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
569 	SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
570 
571 	// Reichweite bestimmen.
572 	if ( !( nStyle & SFXWB_NOREMOTE ) )
573 	{
574 		_pImp->_nState |= FILEDLG_STATE_REMOTE;
575 	}
576 
577 	// Kontrollelement erzeugen, wobei die Reihenfolge die Tab-Steuerung
578 	// bestimmt.
579 	_pImp->_pFtFileName = new FixedText( this, SvtResId( FT_EXPLORERFILE_FILENAME ) );
580 
581     SvtURLBox* pURLBox = new SvtURLBox( this );
582     pURLBox->SetUrlFilter( &m_aURLFilter );
583     _pImp->_pEdFileName = pURLBox;
584 
585     Edit aDummy( this, SvtResId( ED_EXPLORERFILE_FILENAME ) );
586     _pImp->_pEdFileName->SetPosSizePixel( aDummy.GetPosPixel(), aDummy.GetSizePixel() );
587     _pImp->_pEdFileName->Show();
588     pURLBox->SetSelectHdl( LINK( this, SvtFileDialog, EntrySelectHdl_Impl ) );
589     pURLBox->SetOpenHdl( STATIC_LINK( this, SvtFileDialog, OpenHdl_Impl ) );
590 
591     // in folder picker mode, only auto-complete directories (no files)
592     bool bIsFolderPicker = ( _pImp->_eDlgType == FILEDLG_TYPE_PATHDLG );
593     pURLBox->SetOnlyDirectories( bIsFolderPicker );
594 
595     // in save mode, don't use the autocompletion as selection in the edit part
596     bool bSaveMode = ( FILEDLG_MODE_SAVE == _pImp->_eMode );
597     pURLBox->SetNoURLSelection( bSaveMode );
598 
599     _pImp->_pEdFileName->SetHelpId( HID_FILEDLG_AUTOCOMPLETEBOX );
600 
601     _pImp->_pFtFileType = new FixedText( this, SvtResId( FT_EXPLORERFILE_FILETYPE ) );
602 	_pImp->CreateFilterListControl( this, SvtResId( LB_EXPLORERFILE_FILETYPE ) );
603 
604 	// move the filter listbox to the space occupied by the version listbox
605     // if that box isn't needed
606     if ( !( _nExtraBits & SFX_EXTRA_SHOWVERSIONS ) &&
607          !( _nExtraBits & SFX_EXTRA_TEMPLATES ) &&
608          !( _nExtraBits & SFX_EXTRA_IMAGE_TEMPLATE ) )
609 	{
610 		{
611 			FixedText aSharedListBoxLabel( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
612 			_pImp->_pFtFileType->SetPosPixel( aSharedListBoxLabel.GetPosPixel() );
613 		}
614 
615 		{
616 			ListBox aSharedListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
617 			_pImp->GetFilterListControl()->SetPosPixel( aSharedListBox.GetPosPixel() );
618 		}
619 	}
620 
621 	_pImp->_pFtCurrentPath = new FixedText( this, SvtResId( FT_EXPLORERFILE_CURRENTPATH ) );
622     WinBits nTmpStyle = _pImp->_pFtCurrentPath->GetStyle();
623     nTmpStyle |= WB_PATHELLIPSIS;
624     _pImp->_pFtCurrentPath->SetStyle( nTmpStyle );
625 
626     _pImp->_pBtnFileOpen = new PushButton( this, SvtResId( BTN_EXPLORERFILE_OPEN ) );
627 	_pImp->_pBtnCancel = new CancelButton( this, SvtResId( BTN_EXPLORERFILE_CANCEL ) );
628 	_pImp->_pBtnHelp = new HelpButton( this, SvtResId( BTN_EXPLORERFILE_HELP ) );
629 
630 	_pImp->_pBtnUp = new SvtUpButton_Impl( this, SvtResId( BTN_EXPLORERFILE_UP ) );
631 	_pImp->_pBtnNewFolder = new ImageButton( this, SvtResId( BTN_EXPLORERFILE_NEWFOLDER ) );
632 	_pImp->_pBtnNewFolder->SetStyle( _pImp->_pBtnNewFolder->GetStyle() | WB_NOPOINTERFOCUS );
633     _pImp->_pBtnStandard = new SvtTravelButton_Impl( this, SvtResId( BTN_EXPLORERFILE_STANDARD ) );
634 
635 	_pImp->_pBtnUp->SetAccessibleName( _pImp->_pBtnUp->GetQuickHelpText() );
636 	_pImp->_pBtnNewFolder->SetAccessibleName( _pImp->_pBtnNewFolder->GetQuickHelpText() );
637 	_pImp->_pBtnStandard->SetAccessibleName( _pImp->_pBtnStandard->GetQuickHelpText() );
638 
639 	if ( ( nStyle & SFXWB_MULTISELECTION ) == SFXWB_MULTISELECTION )
640 		_pImp->_bMultiSelection = sal_True;
641 
642 	_pFileView = new SvtFileView( this, SvtResId( CTL_EXPLORERFILE_FILELIST ),
643 									   FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType,
644 									   _pImp->_bMultiSelection );
645     _pFileView->SetUrlFilter( &m_aURLFilter );
646 	_pFileView->EnableAutoResize();
647 
648 	_pFileView->SetHelpId( HID_FILEDLG_STANDARD );
649 	_pFileView->SetStyle( _pFileView->GetStyle() | WB_TABSTOP );
650 
651 	// Positionen und Groessen der Knoepfe bestimmen.
652 	Image aNewFolderImg( GetButtonImage( IMG_FILEDLG_CREATEFOLDER ) );
653 	_pImp->_pBtnNewFolder->SetModeImage( aNewFolderImg );
654 
655 	Size aSize( aNewFolderImg.GetSizePixel() );
656 	aSize.Width() += FILEDIALOG_DEF_IMAGEBORDER;
657 	aSize.Height() += FILEDIALOG_DEF_IMAGEBORDER;
658 	_pImp->_pBtnNewFolder->SetSizePixel( aSize );
659 	_pImp->_pBtnUp->SetSizePixel( aSize );
660 	_pImp->_pBtnStandard->SetSizePixel( aSize );
661 
662 	Size aDlgSize = GetOutputSizePixel();
663 	long n6AppFontInPixel =
664 			LogicToPixel( Size( 6, 0 ), MAP_APPFONT ).Width();
665 	long n3AppFontInPixel =
666 			LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
667 
668     // calculate the length of all buttons
669 	const sal_uInt16 nBtnCount = 3; // "previous level", "new folder" and "standard dir"
670 	long nDelta = n6AppFontInPixel; // right border
671 	nDelta += ( nBtnCount * aSize.Width() ); // button count * button width
672 	nDelta += ( n3AppFontInPixel + n3AppFontInPixel / 2 ); // spacing 1*big 1*small
673 
674     Point aPos(
675         aDlgSize.Width() - nDelta,
676         _pImp->_pBtnUp->GetPosPixel().Y()
677     );
678     Size aCurPathSize(
679         aPos.X() - n6AppFontInPixel,
680         _pImp->_pFtCurrentPath->GetOutputSizePixel().Height()
681     );
682 	_pImp->_pFtCurrentPath->SetOutputSizePixel( aCurPathSize );
683 	_pImp->_pBtnUp->SetPosPixel( aPos );
684 	aPos.X() += aSize.Width();
685 	aPos.X() += n3AppFontInPixel;
686 	_pImp->_pBtnNewFolder->SetPosPixel( aPos );
687 	aPos.X() += aSize.Width();
688 	aPos.X() += n3AppFontInPixel / 2;
689 	_pImp->_pBtnStandard->SetPosPixel( aPos );
690 	nDelta = aSize.Height();
691 	nDelta -= aCurPathSize.Height();
692 	nDelta /= 2;
693 	Point aCurPathPos = _pImp->_pFtCurrentPath->GetPosPixel();
694 	aCurPathPos.Y() += nDelta;
695 	_pImp->_pFtCurrentPath->SetPosPixel( aCurPathPos );
696 
697     if ( nStyle & SFXWB_READONLY )
698     {
699         _pCbReadOnly = new CheckBox( this, SvtResId( CB_EXPLORERFILE_READONLY ) );
700         _pCbReadOnly->SetHelpId( HID_FILEOPEN_READONLY );
701         _pCbReadOnly->SetText( SvtResId( STR_SVT_FILEPICKER_READONLY ) );
702         AddControl( _pCbReadOnly );
703         ReleaseOwnerShip( _pCbReadOnly );
704         _pCbReadOnly->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
705     }
706 
707     if ( nStyle & SFXWB_PASSWORD )
708     {
709         _pImp->_pCbPassword = new CheckBox( this, SvtResId( CB_EXPLORERFILE_PASSWORD ) );
710         _pImp->_pCbPassword->SetText( SvtResId( STR_SVT_FILEPICKER_PASSWORD ) );
711         AddControl( _pImp->_pCbPassword );
712         ReleaseOwnerShip( _pImp->_pCbPassword );
713         _pImp->_pCbPassword->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
714     }
715 
716     // set the ini file for extracting the size
717     _pImp->_aIniKey = IODLG_CONFIGNAME;
718 
719     AddControls_Impl( );
720 
721 	// Zahl der Pixel bestimmen, um die die anderen Elemente in der Position
722 	// Angepasst werden muessen.
723 	aPos.Y() += aSize.Height();
724 	aPos.Y() += LogicToPixel( Size( 0, 6 ), MAP_APPFONT ).Height();
725 	long nYOffset = aPos.Y();
726 	aPos = _pFileView->GetPosPixel();
727 	nYOffset -= aPos.Y();
728 
729 	// Positionen der uebrigen Elemente anpassen.
730 	aPos.Y() += nYOffset;
731 	_pFileView->SetPosPixel( aPos );
732 
733 	lcl_MoveControl( _pImp->_pFtFileName, 0, nYOffset );
734 	lcl_MoveControl( _pImp->_pEdFileName, 0, nYOffset );
735 
736 	lcl_MoveControl( _pImp->_pFtFileVersion, 0, nYOffset );
737 	lcl_MoveControl( _pImp->_pLbFileVersion, 0, nYOffset );
738 
739 	lcl_MoveControl( _pImp->_pFtTemplates, 0, nYOffset );
740 	lcl_MoveControl( _pImp->_pLbTemplates, 0, nYOffset );
741 
742 	lcl_MoveControl( _pImp->_pFtImageTemplates, 0, nYOffset );
743 	lcl_MoveControl( _pImp->_pLbImageTemplates, 0, nYOffset );
744 
745 	lcl_MoveControl( _pImp->_pFtFileType, 0, nYOffset );
746 	lcl_MoveControl( _pImp->GetFilterListControl(), 0, nYOffset );
747 
748 	lcl_MoveControl( _pImp->_pBtnFileOpen, 0, nYOffset );
749 	lcl_MoveControl( _pImp->_pBtnCancel, 0, nYOffset );
750 
751 	lcl_MoveControl( _pImp->_pBtnHelp, 0, nYOffset + 3 );
752 		// a little more spacing between Cancel- and HelpButton
753 
754 	// Groesse des Dialoges anpassen.
755 	aSize = GetSizePixel();
756 	aSize.Height() += nYOffset;
757 	SetSizePixel( aSize );
758 
759 	// Beschriftungen dem Modus anpassen.
760 	sal_uInt16 nResId = STR_EXPLORERFILE_OPEN;
761 	sal_uInt16 nButtonResId = 0;
762 
763 	if ( nStyle & WB_SAVEAS )
764 	{
765 		nResId = STR_EXPLORERFILE_SAVE;
766 		nButtonResId = STR_EXPLORERFILE_BUTTONSAVE;
767 	}
768 
769 	if ( ( nStyle & SFXWB_PATHDIALOG ) == SFXWB_PATHDIALOG )
770 	{
771 		_pImp->_pFtFileName->SetText( SvtResId( STR_PATHNAME ) );
772 		nResId = STR_PATHSELECT;
773 		nButtonResId = STR_BUTTONSELECT;
774 	}
775 
776 	SetText( SvtResId( nResId ) );
777 
778 	if ( nButtonResId )
779 		_pImp->_pBtnFileOpen->SetText( SvtResId( nButtonResId ) );
780 
781 	if ( FILEDLG_TYPE_FILEDLG != _pImp->_eDlgType )
782 	{
783 		_pImp->_pFtFileType->Hide();
784 		_pImp->GetFilterListControl()->Hide();
785 	}
786 
787 	// Einstellungen der Steuerelemente vornehmen.
788 	_pImp->_pBtnNewFolder->SetClickHdl( STATIC_LINK( this, SvtFileDialog, NewFolderHdl_Impl ) );
789 	_pImp->_pBtnFileOpen->SetClickHdl( STATIC_LINK( this, SvtFileDialog, OpenHdl_Impl ) );
790 	_pImp->_pBtnCancel->SetClickHdl( LINK( this, SvtFileDialog, CancelHdl_Impl ) );
791 	_pImp->SetFilterListSelectHdl( STATIC_LINK( this, SvtFileDialog, FilterSelectHdl_Impl ) );
792 	_pImp->_pEdFileName->SetGetFocusHdl( STATIC_LINK( this, SvtFileDialog, FileNameGetFocusHdl_Impl ) );
793 	_pImp->_pEdFileName->SetModifyHdl( STATIC_LINK( this, SvtFileDialog, FileNameModifiedHdl_Impl ) );
794 	_pFileView->SetSelectHdl( LINK( this, SvtFileDialog, SelectHdl_Impl ) );
795 	_pFileView->SetDoubleClickHdl( LINK( this, SvtFileDialog, DblClickHdl_Impl ) );
796 	_pFileView->SetOpenDoneHdl( LINK( this, SvtFileDialog, OpenDoneHdl_Impl ) );
797 
798 	// Resourcen freigeben.
799 	FreeResource();
800 
801 	// Timer fuer Filterbox Travel setzen
802 	_pImp->_aFilterTimer.SetTimeout( TRAVELFILTER_TIMEOUT );
803 	_pImp->_aFilterTimer.SetTimeoutHdl( STATIC_LINK( this, SvtFileDialog, FilterSelectHdl_Impl ) );
804 
805 	if ( WB_SAVEAS & nStyle )
806 	{
807 		// different help ids if in save-as mode
808 		// 90744 - 09.08.2001 - frank.schoenheit@sun.com
809 		SetHelpId( HID_FILESAVE_DIALOG );
810 
811 		_pImp->_pEdFileName->SetHelpId( HID_FILESAVE_FILEURL );
812 		_pImp->_pBtnFileOpen->SetHelpId( HID_FILESAVE_DOSAVE );
813 		_pImp->_pBtnNewFolder->SetHelpId( HID_FILESAVE_CREATEDIRECTORY );
814 		_pImp->_pBtnStandard->SetHelpId( HID_FILESAVE_DEFAULTDIRECTORY );
815 		_pImp->_pBtnUp->SetHelpId( HID_FILESAVE_LEVELUP );
816 		_pImp->GetFilterListControl()->SetHelpId( HID_FILESAVE_FILETYPE );
817 		_pFileView->SetHelpId( HID_FILESAVE_FILEVIEW );
818 
819 		// formerly, there was only _pLbFileVersion, which was used for 3 different
820 		// use cases. For reasons of maintainability, I introduced extra members (_pLbTemplates, _pLbImageTemplates)
821 		// for the extra use cases, and separated _pLbFileVersion
822 		// I did not find out in which cases the help ID is really needed HID_FILESAVE_TEMPLATE - all
823 		// tests I made lead to a dialog where _no_ of the three list boxes was present.
824 		// 96930 - 15.08.2002 - fs@openoffice.org
825 		if ( _pImp->_pLbFileVersion )
826 			_pImp->_pLbFileVersion->SetHelpId( HID_FILESAVE_TEMPLATE );
827 		if ( _pImp->_pLbTemplates )
828 			_pImp->_pLbTemplates->SetHelpId( HID_FILESAVE_TEMPLATE );
829 		if ( _pImp->_pLbImageTemplates )
830 			_pImp->_pLbImageTemplates->SetHelpId( HID_FILESAVE_TEMPLATE );
831 
832 		if ( _pImp->_pCbPassword ) _pImp->_pCbPassword->SetHelpId( HID_FILESAVE_SAVEWITHPASSWORD );
833 		if ( _pImp->_pCbAutoExtension ) _pImp->_pCbAutoExtension->SetHelpId( HID_FILESAVE_AUTOEXTENSION );
834 		if ( _pImp->_pCbOptions ) _pImp->_pCbOptions->SetHelpId( HID_FILESAVE_CUSTOMIZEFILTER );
835 		if ( _pCbSelection ) _pCbSelection->SetHelpId( HID_FILESAVE_SELECTION );
836 	}
837 
838 	// correct the z-order of the controls
839 	implArrangeControls();
840 
841     // special URLs, such as favourites and "restricted" paths
842     implInitializeSpecialURLLists( );
843 
844     /// read our settings from the configuration
845     m_aConfiguration = OConfigurationTreeRoot::createWithServiceFactory(
846         ::comphelper::getProcessServiceFactory(),
847         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI/FilePicker" ) )
848     );
849 }
850 
851 //*****************************************************************************
852 
853 IMPL_STATIC_LINK( SvtFileDialog, NewFolderHdl_Impl, PushButton*, EMPTYARG )
854 {
855     pThis->_pFileView->EndInplaceEditing( false );
856 
857     INetURLObject aObj( pThis->_pFileView->GetViewURL() );
858 	String sFolderName = aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 );
859     svtools::QueryFolderNameDialog aDlg( pThis, sFolderName, String( SvtResId( STR_SVT_NEW_FOLDER ) ) );
860     sal_Bool bHandled = sal_False;
861 
862 	while ( !bHandled )
863 	{
864 		if ( aDlg.Execute() == RET_OK )
865 			bHandled = pThis->_pFileView->CreateNewFolder( aDlg.GetName() );
866 		else
867 			bHandled = sal_True;
868 	}
869 
870 	return 0;
871 }
872 
873 //*****************************************************************************
874 
875 IMPL_STATIC_LINK_NOINSTANCE( SvtFileDialog, ViewHdl_Impl, ImageButton*, EMPTYARG )
876 {
877 	return 0;
878 }
879 
880 //*****************************************************************************
881 //-----------------------------------------------------------------------------
882 sal_Bool SvtFileDialog::createNewUserFilter( const String& _rNewFilter, sal_Bool _bAllowUserDefExt )
883 {
884 	// delete the old user filter and create a new one
885 	DELETEZ( _pImp->_pUserFilter );
886 	_pImp->_pUserFilter = new SvtFileDialogFilter_Impl( _rNewFilter, _rNewFilter );
887 
888 	// remember the extension
889 	sal_Bool bIsAllFiles = _rNewFilter.EqualsAscii( FILEDIALOG_FILTER_ALL );
890 	if ( bIsAllFiles )
891 		EraseDefaultExt();
892 	else
893 		SetDefaultExt( _rNewFilter.Copy( 2 ) );
894 		// TODO: this is nonsense. In the whole file there are a lotta places where we assume that a user filter
895 		// is always "*.<something>". But changing this would take some more time than I have now ...
896 		// 05.12.2001 - 95486 - fs@openoffice.org
897 
898 	// now, the default extension is set to the one of the user filter (or empty)
899 	// if the former is not allowed (_bAllowUserDefExt = <FALSE/>), we have to use the ext of the current filter
900 	// (if possible)
901 	sal_Bool bUseCurFilterExt = sal_True;
902 	String sUserFilter = _pImp->_pUserFilter->GetType();
903 	xub_StrLen nSepPos = sUserFilter.SearchBackward( '.' );
904 	if ( STRING_NOTFOUND != nSepPos )
905 	{
906 		String sUserExt = sUserFilter.Copy( nSepPos + 1 );
907 		if	(	( STRING_NOTFOUND == sUserExt.Search( '*' ) )
908 			&&	( STRING_NOTFOUND == sUserExt.Search( '?' ) )
909 			)
910 			bUseCurFilterExt = sal_False;
911 	}
912 
913 	if ( !_bAllowUserDefExt || bUseCurFilterExt )
914 	{
915 		if ( _pImp->GetCurFilter( ) )
916             SetDefaultExt( _pImp->GetCurFilter( )->GetExtension() );
917 		else
918 			EraseDefaultExt();
919 	}
920 
921 	// outta here
922 	return bIsAllFiles;
923 }
924 
925 //-----------------------------------------------------------------------------
926 #define FLT_NONEMPTY		0x0001
927 #define FLT_CHANGED			0x0002
928 #define FLT_USERFILTER		0x0004
929 #define FLT_ALLFILESFILTER	0x0008
930 
931 //-----------------------------------------------------------------------------
932 sal_uInt16 SvtFileDialog::adjustFilter( const String& _rFilter )
933 {
934 	sal_uInt16 nReturn = 0;
935 
936 	const sal_Bool bNonEmpty = ( _rFilter.Len() != 0 );
937 	if ( bNonEmpty )
938 	{
939 		nReturn |= FLT_NONEMPTY;
940 
941 		sal_Bool bFilterChanged = sal_True;
942 
943 		// search for a corresponding filter
944 		SvtFileDialogFilter_Impl* pFilter = FindFilter_Impl( _rFilter, sal_False, bFilterChanged );
945 
946 #ifdef AUTOSELECT_USERFILTER
947 		// if we found a filter which without allowing multi-extensions -> select it
948 		if ( pFilter )
949 		{
950 			_pImp->SelectFilterListEntry( pFilter->GetName() );
951 			_pImp->SetCurFilter( pFilter );
952 		}
953 #endif // AUTOSELECT_USERFILTER
954 
955 		// look for multi-ext filters if necessary
956 		if ( !pFilter )
957 			pFilter = FindFilter_Impl( _rFilter, sal_True, bFilterChanged );
958 
959 		if ( bFilterChanged )
960 			nReturn |= FLT_CHANGED;
961 
962 		if ( !pFilter )
963 		{
964 			nReturn |= FLT_USERFILTER;
965 			// no filter found : use it as user defined filter
966 #ifdef AUTOSELECT_USERFILTER
967 			if ( createNewUserFilter( _rFilter, sal_True ) )
968 #else
969 			if ( createNewUserFilter( _rFilter, sal_False ) )
970 #endif
971 			{	// it's the "all files" filter
972 				nReturn |= FLT_ALLFILESFILTER;
973 
974 #ifdef AUTOSELECT_USERFILTER
975 				// select the "all files" entry
976 				String sAllFilesFilter( SvtResId( STR_FILTERNAME_ALL ) );
977 				if ( _pImp->HasFilterListEntry( sAllFilesFilter ) )
978 				{
979 					_pImp->SelectFilterListEntry( sAllFilesFilter );
980 					_pImp->SetCurFilter( _pImp->GetSelectedFilterEntry( sAllFilesFilter ) );
981 				}
982 				else
983 					_pImp->SetNoFilterListSelection( );	// there is no "all files" entry
984 #endif // AUTOSELECT_USERFILTER
985 			}
986 #ifdef AUTOSELECT_USERFILTER
987 			else
988 				_pImp->SetNoFilterListSelection( );
989 #endif // AUTOSELECT_USERFILTER
990 		}
991 	}
992 
993 	return nReturn;
994 }
995 
996 //-----------------------------------------------------------------------------
997 IMPL_LINK( SvtFileDialog, CancelHdl_Impl, void*, EMPTYARG )
998 {
999     if ( m_pCurrentAsyncAction.is() )
1000     {
1001         m_pCurrentAsyncAction->cancel();
1002         onAsyncOperationFinished();
1003     }
1004     else
1005     {
1006         EndDialog( sal_False );
1007     }
1008     return 1L;
1009 }
1010 
1011 //-----------------------------------------------------------------------------
1012 IMPL_STATIC_LINK( SvtFileDialog, OpenHdl_Impl, void*, pVoid )
1013 {
1014 	if ( pThis->_pImp->_bMultiSelection && pThis->_pFileView->GetSelectionCount() > 1 )
1015 	{
1016 		// bei Multiselektion spezielles Open
1017 		pThis->OpenMultiSelection_Impl();
1018 		return 0;
1019 	}
1020 
1021 	String aFileName;
1022     String aOldPath( pThis->_pFileView->GetViewURL() );
1023 	if ( pThis->_pImp->_bDoubleClick || pThis->_pFileView->HasChildPathFocus() )
1024 		// Selection done by doubleclicking in the view, get filename from the view
1025 		aFileName = pThis->_pFileView->GetCurrentURL();
1026 
1027 	if ( !aFileName.Len() )
1028 	{
1029 		// if an entry is selected in the view ....
1030 		if ( pThis->_pFileView->GetSelectionCount() )
1031 		{	// -> use this one. This will allow us to step down this folder
1032 			// #i8928# - 2002-12-20 - fs@openoffice.org
1033 			aFileName = pThis->_pFileView->GetCurrentURL();
1034 		}
1035 	}
1036 
1037 	if ( !aFileName.Len() )
1038 	{
1039 		if ( pThis->_pImp->_eMode == FILEDLG_MODE_OPEN && pThis->_pImp->_pEdFileName->IsTravelSelect() )
1040 			// OpenHdl called from URLBox; travelling through the list of URLs should not cause an opening
1041 			return 0;		            // MBA->PB: seems to be called never ?!
1042 
1043 		// get the URL from from the edit field ( if not empty )
1044 		if ( pThis->_pImp->_pEdFileName->GetText().Len() )
1045 		{
1046 			String aText = pThis->_pImp->_pEdFileName->GetText();
1047 
1048 			// did we reach the root?
1049 			if ( !INetURLObject( aOldPath ).getSegmentCount() )
1050 			{
1051 				if ( ( aText.Len() == 2 && aText.EqualsAscii( ".." ) ) ||
1052 					 ( aText.Len() == 3 && ( aText.EqualsAscii( "..\\" ) || aText.EqualsAscii( "../" ) ) ) )
1053 					// don't go higher than the root
1054 					return 0;
1055 			}
1056 
1057 #if defined( UNX ) || defined( FS_PRIV_DEBUG )
1058 			if ( ( 1 == aText.Len() ) && ( '~' == aText.GetBuffer()[0] ) )
1059 			{
1060 				// go to the home directory
1061 				if ( lcl_getHomeDirectory( pThis->_pFileView->GetViewURL(), aFileName ) )
1062 					// in case we got a home dir, reset the text of the edit
1063 					pThis->_pImp->_pEdFileName->SetText( String() );
1064 			}
1065 			if ( !aFileName.Len() )
1066 #endif
1067 			{
1068 				// get url from autocomplete edit
1069         		aFileName = pThis->_pImp->_pEdFileName->GetURL();
1070 			}
1071 		}
1072 		else if ( pVoid == pThis->_pImp->_pBtnFileOpen )
1073 			// OpenHdl was called for the "Open" Button; if edit field is empty, use selected element in the view
1074 			aFileName = pThis->_pFileView->GetCurrentURL();
1075 	}
1076 
1077 	// MBA->PB: ?!
1078 	if ( !aFileName.Len() && pVoid == pThis->_pImp->_pEdFileName && pThis->_pImp->_pUserFilter )
1079 	{
1080 		DELETEZ( pThis->_pImp->_pUserFilter );
1081 		return 0;
1082 	}
1083 
1084 	sal_uInt16 nLen = aFileName.Len();
1085 	if ( !nLen )
1086 	{
1087 		// if the dialog was opened to select a folder, the last selected folder should be selected
1088 		if( pThis->_pImp->_eDlgType == FILEDLG_TYPE_PATHDLG )
1089 		{
1090 			aFileName =	pThis->_pImp->_pFtCurrentPath->GetText();
1091 			nLen = aFileName.Len();
1092 		}
1093 		else
1094 			// no file selected !
1095 			return 0;
1096 	}
1097 
1098 	// mark input as selected
1099 	pThis->_pImp->_pEdFileName->SetSelection( Selection( 0, nLen ) );
1100 
1101 	// if a path with wildcards is given, divide the string into path and wildcards
1102 	String aFilter;
1103 	if ( !pThis->IsolateFilterFromPath_Impl( aFileName, aFilter ) )
1104 		return 0;
1105 
1106 	// if a filter was retrieved, there were wildcards !
1107 	sal_uInt16 nNewFilterFlags = pThis->adjustFilter( aFilter );
1108 	if ( nNewFilterFlags & FLT_CHANGED )
1109 	{
1110 		// cut off all text before wildcard in edit and select wildcard
1111 		pThis->_pImp->_pEdFileName->SetText( aFilter );
1112 		pThis->_pImp->_pEdFileName->SetSelection( Selection( 0, aFilter.Len() ) );
1113 	}
1114 
1115     {
1116 	    INetURLObject aFileObject( aFileName );
1117 	    if ( ( aFileObject.GetProtocol() == INET_PROT_NOT_VALID ) && aFileName.Len() )
1118 	    {
1119 		    String sCompleted = SvtURLBox::ParseSmart( aFileName, pThis->_pFileView->GetViewURL(), SvtPathOptions().GetWorkPath() );
1120 		    if ( sCompleted.Len() )
1121 			    aFileName = sCompleted;
1122 	    }
1123     }
1124 
1125 	// Pr"ufen, ob es sich um einen Ordner handelt.
1126     sal_Bool bIsFolder = sal_False;
1127 
1128     // first thing before doing anyhing with the content: Reset it. When the user presses "open" (or "save" or "export",
1129     // for that matter), s/he wants the complete handling, including all possible error messages, even if s/he
1130     // does the same thing for the same content twice, s/he wants both fails to be displayed.
1131     // Without the reset, it could be that the content cached all relevant information, and will not display any
1132     // error messages for the same content a second time ....
1133     pThis->m_aContent.bindTo( ::rtl::OUString( ) );
1134 
1135     // #97148# & #102204# ---------
1136 	if ( aFileName.Len() )
1137 	{
1138         // Make sure we have own Interaction Handler in place. We do not need
1139         // to intercept interactions here, but to record the fact that there
1140         // was an interaction.
1141         SmartContent::InteractionHandlerType eInterActionHandlerType
1142             = pThis->m_aContent.queryCurrentInteractionHandler();
1143         if ( ( eInterActionHandlerType == SmartContent::IHT_NONE ) ||
1144              ( eInterActionHandlerType == SmartContent::IHT_DEFAULT ) )
1145             pThis->m_aContent.enableOwnInteractionHandler(
1146                 OFilePickerInteractionHandler::E_NOINTERCEPTION );
1147 
1148 		bIsFolder = pThis->m_aContent.isFolder( aFileName );
1149 
1150         // access denied to the given resource - and interaction was already
1151         // used => break following operations
1152         OFilePickerInteractionHandler* pHandler
1153             = pThis->m_aContent.getOwnInteractionHandler();
1154 
1155         OSL_ENSURE( pHandler, "Got no Interaction Handler!!!" );
1156 
1157         if ( pHandler->wasAccessDenied() )
1158             return 0;
1159 
1160 		if ( pThis->m_aContent.isInvalid() &&
1161              ( pThis->_pImp->_eMode == FILEDLG_MODE_OPEN ) )
1162         {
1163             if ( !pHandler->wasUsed() )
1164                 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS );
1165 
1166 			return 0;
1167         }
1168 
1169         // restore previous Interaction Handler
1170         if ( eInterActionHandlerType == SmartContent::IHT_NONE )
1171             pThis->m_aContent.disableInteractionHandler();
1172         else if ( eInterActionHandlerType == SmartContent::IHT_DEFAULT )
1173             pThis->m_aContent.enableDefaultInteractionHandler();
1174  	}
1175 
1176     if  (   !bIsFolder                                      // no existent folder
1177 		&&	pThis->_pImp->_pCbAutoExtension					// auto extension is enabled in general
1178 		&&	pThis->_pImp->_pCbAutoExtension->IsChecked()	// auto extension is really to be used
1179 		&&	pThis->GetDefaultExt().Len()					// there is a default extension
1180 		&&	pThis->GetDefaultExt() != '*'					// the default extension is not "all"
1181         && !(   FILEDLG_MODE_SAVE == pThis->_pImp->_eMode       // we're saving a file
1182             &&  pThis->_pFileView->GetSelectionCount()          // there is a selected file in the file view -> it will later on
1183             )                                                   //    (in SvtFileDialog::GetPathList) be taken as file to save to
1184                                                                 // (#114818# - 2004-03-17 - fs@openoffice.org)
1185         && FILEDLG_MODE_OPEN != pThis->_pImp->_eMode // pb: #i83408# don't append extension on open
1186         )
1187 	{
1188         // check extension and append the default extension if necessary
1189         appendDefaultExtension(aFileName,
1190                                pThis->GetDefaultExt(),
1191                                pThis->_pImp->GetCurFilter()->GetType());
1192 	}
1193 
1194 	sal_Bool bOpenFolder = ( FILEDLG_TYPE_PATHDLG == pThis->_pImp->_eDlgType ) &&
1195 					   !pThis->_pImp->_bDoubleClick && pVoid != pThis->_pImp->_pEdFileName;
1196 	if ( bIsFolder )
1197 	{
1198 		if ( bOpenFolder )
1199 		{
1200 			pThis->_aPath = aFileName;
1201 		}
1202         else
1203         {
1204 		    if ( aFileName != pThis->_pFileView->GetViewURL() )
1205 		    {
1206                 if ( !pThis->m_aURLFilter.isUrlAllowed( aFileName ) )
1207                 {
1208                     pThis->simulateAccessDenied( aFileName );
1209     			    return 0;
1210                 }
1211 
1212                 pThis->OpenURL_Impl( aFileName );
1213 		    }
1214 		    else
1215             {
1216                 if ( nNewFilterFlags & FLT_CHANGED )
1217                     pThis->ExecuteFilter();
1218             }
1219 
1220             return 0;
1221         }
1222 	}
1223     else if ( !( nNewFilterFlags & FLT_NONEMPTY ) )
1224 	{
1225 		// Ggf. URL speichern.
1226         pThis->_aPath = aFileName;
1227 	}
1228 	else
1229 	{
1230 		// Ggf. neu filtern.
1231 		if ( nNewFilterFlags & FLT_CHANGED )
1232 			pThis->ExecuteFilter();
1233 		return 0;
1234 	}
1235 
1236     INetURLObject aFileObj( aFileName );
1237     if ( aFileObj.HasError() )
1238     {
1239         ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
1240         return 0;
1241     }
1242 
1243     // if restrictions for the allowed folders are in place, we need to do a check here
1244     if ( !pThis->m_aURLFilter.isUrlAllowed( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
1245     {
1246         pThis->simulateAccessDenied( aFileName );
1247         return 0;
1248     }
1249 
1250 	switch ( pThis->_pImp->_eMode )
1251 	{
1252 		case FILEDLG_MODE_SAVE:
1253 		{
1254 			if ( ::utl::UCBContentHelper::Exists( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
1255 			{
1256 				QueryBox aBox( pThis, WB_YES_NO, SvtResId( STR_SVT_ALREADYEXISTOVERWRITE ) );
1257 				if ( aBox.Execute() != RET_YES )
1258 					return 0;
1259 			}
1260 			else
1261 			{
1262 				String aCurPath;
1263 				if ( ::utl::LocalFileHelper::ConvertURLToSystemPath( aFileName, aCurPath ) )
1264 				{
1265 					// if content does not exist: at least its path must exist
1266 					INetURLObject aPathObj = aFileObj;
1267 					aPathObj.removeSegment();
1268 					// #97148# & #102204# ------------
1269 					sal_Bool bFolder = pThis->m_aContent.isFolder( aPathObj.GetMainURL( INetURLObject::NO_DECODE ) );
1270 					if ( !bFolder )
1271 					{
1272 						ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH );
1273 						return 0;
1274 					}
1275 				}
1276 			}
1277 		}
1278 		break;
1279 
1280 		case FILEDLG_MODE_OPEN:
1281 		{
1282 			// do an existence check herein, again
1283 			// 16.11.2001 - 93107 - frank.schoenheit@sun.com
1284 
1285 			if ( INET_PROT_FILE == aFileObj.GetProtocol( ) )
1286 			{
1287 				sal_Bool bExists = sal_False;
1288 				// #102204# --------------
1289 				bExists = pThis->m_aContent.is( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) );
1290 
1291 
1292 				if ( !bExists )
1293 				{
1294 					String sError( SvtResId( RID_FILEOPEN_NOTEXISTENTFILE ) );
1295 
1296 					String sInvalidFile( aFileObj.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
1297 					if ( INET_PROT_FILE == aFileObj.GetProtocol() )
1298 					{	// if it's a file URL, transform the URL into system notation
1299 						::rtl::OUString sURL( sInvalidFile );
1300 						::rtl::OUString sSystem;
1301 						osl_getSystemPathFromFileURL( sURL.pData, &sSystem.pData );
1302 						sInvalidFile = sSystem;
1303 					}
1304 					sError.SearchAndReplaceAscii( "$name$", sInvalidFile );
1305 
1306 					ErrorBox aError( pThis, WB_OK, sError );
1307 					aError.Execute();
1308 					return 0;
1309 				}
1310 			}
1311 		}
1312 		break;
1313 
1314 		default:
1315 			DBG_ERROR("SvtFileDialog, OpenHdl_Impl: invalid mode!");
1316 	}
1317 
1318 	// Interessenten benachrichtigen.
1319 	long nRet;
1320 
1321 	if ( pThis->_aOKHdl.IsSet() )
1322 		nRet = pThis->_aOKHdl.Call( pThis );
1323 	else
1324 		nRet = pThis->OK();
1325 
1326 	if ( nRet )
1327 	{
1328 		pThis->EndDialog( sal_True );
1329 	}
1330 
1331 	return nRet;
1332 }
1333 
1334 //*****************************************************************************
1335 
1336 void SvtFileDialog::EnableAutocompletion( sal_Bool _bEnable )
1337 {
1338     _pImp->_pEdFileName->EnableAutocompletion( _bEnable );
1339 }
1340 
1341 //*****************************************************************************
1342 
1343 IMPL_STATIC_LINK( SvtFileDialog, FilterSelectHdl_Impl, ListBox*, pBox )
1344 {
1345 	DBG_ASSERT( pBox, "SvtFileDialog:keine Instanz" );
1346 
1347 	// wurde der Handler vom Travel-Timer gefeuert?
1348 	if ( pBox == (ListBox*)&pThis->_pImp->_aFilterTimer )
1349 	{
1350 		// Anzeige erneut filtern.
1351 		pThis->ExecuteFilter();
1352 		return 0;
1353 	}
1354 
1355 	String sSelectedFilterDisplayName;
1356 	SvtFileDialogFilter_Impl* pSelectedFilter = pThis->_pImp->GetSelectedFilterEntry( sSelectedFilterDisplayName );
1357 	if ( !pSelectedFilter )
1358 	{	// there is no current selection. This happens if for instance the user selects a group separator using
1359 		// the keyboard, and then presses enter: When the selection happens, we immediately deselect the entry,
1360 		// so in this situation there is no current selection.
1361 		if ( restoreCurrentFilter( pThis->_pImp ) )
1362 			pThis->ExecuteFilter();
1363 	}
1364 	else
1365 	{
1366 		if ( pSelectedFilter->isGroupSeparator() )
1367 		{	// group separators can't be selected
1368 			// return to the previously selected entry
1369 			if ( pThis->_pImp->IsFilterListTravelSelect() )
1370 			{
1371 				pThis->_pImp->SetNoFilterListSelection( );
1372 
1373 				// stop the timer for executing the filter
1374 				if ( pThis->_pImp->_aFilterTimer.IsActive() )
1375 					pThis->_pImp->m_bNeedDelayedFilterExecute = sal_True;
1376 				pThis->_pImp->_aFilterTimer.Stop();
1377 			}
1378 			else
1379 			{
1380 				if ( restoreCurrentFilter( pThis->_pImp ) )
1381 					pThis->ExecuteFilter();
1382 			}
1383 		}
1384 		else if	(	( pSelectedFilter != pThis->_pImp->GetCurFilter() )
1385 				||	pThis->_pImp->_pUserFilter
1386 				)
1387 		{
1388             // Store the old filter for the auto extension handling
1389             String sLastFilterExt = pThis->_pImp->GetCurFilter()->GetExtension();
1390 			DELETEZ( pThis->_pImp->_pUserFilter );
1391 
1392             // Ggf. Filter des Benutzers entfernen.
1393 			pThis->_pImp->SetCurFilter( pSelectedFilter, sSelectedFilterDisplayName );
1394 
1395 			// Ggf. Endung anzeigen.
1396             pThis->SetDefaultExt( pSelectedFilter->GetExtension() );
1397 			sal_uInt16 nSepPos = pThis->GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP );
1398 
1399 			if ( nSepPos != STRING_NOTFOUND )
1400 				pThis->EraseDefaultExt( nSepPos );
1401 
1402 			// update the extension of the current file if necessary
1403             lcl_autoUpdateFileExtension( pThis, sLastFilterExt );
1404 
1405 			// wenn der Benutzer schnell durch die Filterbox
1406 			// travelt, nicht sofort Filtern
1407 			if ( pThis->_pImp->IsFilterListTravelSelect() )
1408 			{
1409 				// FilterSelectHdl_Impl soll in
1410 				// TRAVELFILTER_TIMEOUT ms neu gefeuert werden
1411 				pThis->_pImp->_aFilterTimer.Start();
1412 			}
1413 			else
1414 			{
1415 				// evtl. vorher gestarteten Timer stoppen
1416 				pThis->_pImp->_aFilterTimer.Stop();
1417 
1418 				// Anzeige erneut filtern.
1419 				pThis->ExecuteFilter();
1420 			}
1421 		}
1422 	}
1423 
1424 	return 0;
1425 }
1426 
1427 //*****************************************************************************
1428 
1429 IMPL_STATIC_LINK( SvtFileDialog, FileNameGetFocusHdl_Impl, void*, EMPTYARG )
1430 {
1431 	pThis->_pFileView->SetNoSelection();
1432 	pThis->_pFileView->Update();
1433 	return 0;
1434 }
1435 
1436 //*****************************************************************************
1437 
1438 IMPL_STATIC_LINK( SvtFileDialog, FileNameModifiedHdl_Impl, void*, EMPTYARG )
1439 {
1440 	FileNameGetFocusHdl_Impl( pThis, NULL );
1441 	return 0;
1442 }
1443 
1444 //*****************************************************************************
1445 
1446 SvtFileDialogFilter_Impl* SvtFileDialog::FindFilter_Impl
1447 (
1448 	const String& _rFilter,
1449 	sal_Bool _bMultiExt,/*	sal_True - auch Filter mit mehreren Endungen
1450 							beruecksichtigen
1451 							sal_False - keine ...
1452 						*/
1453 	sal_Bool& _rFilterChanged
1454 )
1455 
1456 /*	[Beschreibung]
1457 
1458 	Die Methode sucht in den eingef"ugten Filtern nach der
1459 	spezifizierten Endung.
1460 */
1461 
1462 {
1463 	SvtFileDialogFilter_Impl* pFoundFilter = NULL;
1464 	SvtFileDialogFilterList_Impl* pList = _pImp->_pFilter;
1465 	sal_uInt16 nFilter = pList->Count();
1466 
1467 	while ( nFilter-- )
1468 	{
1469 		SvtFileDialogFilter_Impl* pFilter = pList->GetObject( nFilter );
1470 		const String& rType = pFilter->GetType();
1471 		String aSingleType = rType;
1472 
1473 		if ( _bMultiExt )
1474 		{
1475 			sal_uInt16 nIdx = 0;
1476 			while ( !pFoundFilter && nIdx != STRING_NOTFOUND )
1477 			{
1478 				aSingleType = rType.GetToken( 0, FILEDIALOG_DEF_EXTSEP, nIdx );
1479 #ifdef UNX
1480 				if ( aSingleType.CompareTo( _rFilter ) == COMPARE_EQUAL )
1481 #else
1482 				if ( aSingleType.CompareIgnoreCaseToAscii( _rFilter ) == COMPARE_EQUAL )
1483 #endif
1484 					pFoundFilter = pFilter;
1485 			}
1486 		}
1487 #ifdef UNX
1488 		else if ( rType.CompareTo( _rFilter ) == COMPARE_EQUAL )
1489 #else
1490 		else if ( rType.CompareIgnoreCaseToAscii( _rFilter ) == COMPARE_EQUAL )
1491 #endif
1492 			pFoundFilter = pFilter;
1493 
1494 		if ( pFoundFilter )
1495 		{
1496 			// Filter aktivieren.
1497 			_rFilterChanged = _pImp->_pUserFilter || ( _pImp->GetCurFilter() != pFilter );
1498 
1499 			createNewUserFilter( _rFilter, sal_False );
1500 
1501 			break;
1502 		}
1503 	}
1504 	return pFoundFilter;
1505 }
1506 
1507 //*****************************************************************************
1508 
1509 void SvtFileDialog::ExecuteFilter()
1510 {
1511 	_pImp->m_bNeedDelayedFilterExecute = sal_False;
1512     executeAsync( AsyncPickerAction::eExecuteFilter, String(), getMostCurrentFilter( _pImp ) );
1513 }
1514 
1515 //*****************************************************************************
1516 
1517 void SvtFileDialog::OpenMultiSelection_Impl()
1518 
1519 /*	[Beschreibung]
1520 
1521 	OpenHandler f"ur MultiSelektion
1522 */
1523 
1524 {
1525 	String aPath;
1526 	sal_uLong nCount = _pFileView->GetSelectionCount();
1527 	SvLBoxEntry* pEntry = nCount ? _pFileView->FirstSelected() : NULL;
1528 
1529 	if ( nCount && pEntry )
1530 		_aPath = _pFileView->GetURL( pEntry );
1531 
1532 	// Interessenten benachrichtigen.
1533 	long nRet;
1534 
1535 	if ( _aOKHdl.IsSet() )
1536 		nRet = _aOKHdl.Call( this );
1537 	else
1538 		nRet = OK();
1539 
1540 	if ( nRet )
1541 		EndDialog( sal_True );
1542 }
1543 
1544 //*****************************************************************************
1545 
1546 void SvtFileDialog::UpdateControls( const String& rURL )
1547 {
1548    	_pImp->_pEdFileName->SetBaseURL( rURL );
1549 
1550 	INetURLObject aObj( rURL );
1551 
1552     //=========================================================================
1553 	{
1554 		String sText;
1555 		DBG_ASSERT( INET_PROT_NOT_VALID != aObj.GetProtocol(), "SvtFileDialog::UpdateControls: Invalid URL!" );
1556 
1557 		if ( aObj.getSegmentCount() )
1558 		{
1559 			::utl::LocalFileHelper::ConvertURLToSystemPath( rURL, sText );
1560 			if ( sText.Len() )
1561 			{
1562 				// no Fsys path for server file system ( only UCB has mountpoints! )
1563 				if ( INET_PROT_FILE != aObj.GetProtocol() )
1564                     sText = rURL.Copy( static_cast< sal_uInt16 >(
1565                         INetURLObject::GetScheme( aObj.GetProtocol() ).getLength() ) );
1566 			}
1567 
1568 			if ( !sText.Len() && aObj.getSegmentCount() )
1569 				sText = rURL;
1570 		}
1571 
1572 		// path mode ?
1573 		if ( FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType )
1574 			// -> set new path in the edit field
1575 			_pImp->_pEdFileName->SetText( sText );
1576 
1577 		// in the "current path" field, truncate the trailing slash
1578 		if ( aObj.hasFinalSlash() )
1579 		{
1580 			aObj.removeFinalSlash();
1581 			String sURL( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1582 			if ( !::utl::LocalFileHelper::ConvertURLToSystemPath( sURL, sText ) )
1583 				sText = sURL;
1584 		}
1585 
1586         if ( !sText.Len() && rURL.Len() )
1587             // happens, for instance, for URLs which the INetURLObject does not know to belong to a hierarchical scheme
1588             sText = rURL;
1589 		_pImp->_pFtCurrentPath->SetText( sText );
1590 	}
1591 
1592     //=========================================================================
1593     _aPath = rURL;
1594     if ( _pFileNotifier )
1595 		_pFileNotifier->notify( DIRECTORY_CHANGED, 0 );
1596 }
1597 
1598 //*****************************************************************************
1599 
1600 IMPL_LINK( SvtFileDialog, SelectHdl_Impl, SvTabListBox*, pBox )
1601 {
1602 	SvLBoxEntry* pEntry = pBox->FirstSelected();
1603 	DBG_ASSERT( pEntry, "SelectHandler without selected entry" );
1604 	SvtContentEntry* pUserData = (SvtContentEntry*)pEntry->GetUserData();
1605 
1606 	if ( pUserData )
1607 	{
1608 		INetURLObject aObj( pUserData->maURL );
1609 		if ( FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType )
1610 		{
1611 			if ( aObj.GetProtocol() == INET_PROT_FILE )
1612 			{
1613 				if ( !pUserData->mbIsFolder )
1614 					aObj.removeSegment();
1615 				String aName = aObj.getFSysPath( (INetURLObject::FSysStyle)(INetURLObject::FSYS_DETECT & ~INetURLObject::FSYS_VOS) );
1616 				_pImp->_pEdFileName->SetText( aName );
1617 				_pImp->_pEdFileName->SetSelection( Selection( 0, aName.Len() ) );
1618 				_aPath = pUserData->maURL;
1619 			}
1620 			else if ( !pUserData->mbIsFolder )
1621 			{
1622 				_pImp->_pEdFileName->SetText( pUserData->maURL );
1623 				_pImp->_pEdFileName->SetSelection( Selection( 0, pUserData->maURL.Len() ) );
1624 				_aPath = pUserData->maURL;
1625 			}
1626 			else
1627 				_pImp->_pEdFileName->SetText( UniString() );
1628 		}
1629 		else
1630 		{
1631 			if ( !pUserData->mbIsFolder )
1632 			{
1633 				String aName = pBox->GetEntryText( pEntry, 0 );
1634 				_pImp->_pEdFileName->SetText( aName );
1635 				_pImp->_pEdFileName->SetSelection( Selection( 0, aName.Len() ) );
1636 				_aPath = pUserData->maURL;
1637 			}
1638 		}
1639 	}
1640 
1641 	if ( _pImp->_bMultiSelection && _pFileView->GetSelectionCount() > 1 )
1642 	{
1643 		// bei Multiselektion den Datei-Edit leeren
1644 		_pImp->_pEdFileName->SetText( String() );
1645 	}
1646 
1647 	FileSelect();
1648 
1649 	return 0;
1650 }
1651 
1652 //*****************************************************************************
1653 
1654 IMPL_LINK( SvtFileDialog, DblClickHdl_Impl, SvTabListBox*, EMPTYARG )
1655 {
1656 	_pImp->_bDoubleClick = sal_True;
1657 	OpenHdl_Impl( this, NULL );
1658 	_pImp->_bDoubleClick = sal_False;
1659 
1660 	return 0;
1661 }
1662 
1663 //*****************************************************************************
1664 
1665 IMPL_LINK( SvtFileDialog, EntrySelectHdl_Impl, ComboBox*, EMPTYARG )
1666 {
1667 	FileSelect();
1668 
1669     return 0;
1670 }
1671 
1672 //*****************************************************************************
1673 
1674 IMPL_LINK( SvtFileDialog, OpenDoneHdl_Impl, SvtFileView*, pView )
1675 {
1676     String sCurrentFolder( pView->GetViewURL() );
1677     // check if we can create new folders
1678     EnableControl( _pImp->_pBtnNewFolder, ContentCanMakeFolder( sCurrentFolder ) && m_aURLFilter.isUrlAllowed( sCurrentFolder, false ) );
1679 
1680     // check if we can travel one level up
1681     bool bCanTravelUp = ContentHasParentFolder( pView->GetViewURL() );
1682     if ( bCanTravelUp )
1683     {
1684         // additional check: the parent folder should not be prohibited
1685         INetURLObject aCurrentFolder( sCurrentFolder );
1686         DBG_ASSERT( INET_PROT_NOT_VALID != aCurrentFolder.GetProtocol(),
1687             "SvtFileDialog::OpenDoneHdl_Impl: invalid current URL!" );
1688 
1689         aCurrentFolder.removeSegment();
1690         bCanTravelUp &= m_aURLFilter.isUrlAllowed( aCurrentFolder.GetMainURL( INetURLObject::NO_DECODE ) );
1691     }
1692     EnableControl( _pImp->_pBtnUp, bCanTravelUp );
1693 
1694 	return 0;
1695 }
1696 
1697 //*****************************************************************************
1698 
1699 IMPL_LINK( SvtFileDialog, AutoExtensionHdl_Impl, CheckBox*, EMPTYARG )
1700 {
1701 	if ( _pFileNotifier )
1702 		_pFileNotifier->notify( CTRL_STATE_CHANGED,
1703                                 CHECKBOX_AUTOEXTENSION );
1704 
1705 	// update the extension of the current file if necessary
1706     lcl_autoUpdateFileExtension( this, _pImp->GetCurFilter()->GetExtension() );
1707 
1708     return 0;
1709 }
1710 
1711 //*****************************************************************************
1712 
1713 IMPL_LINK( SvtFileDialog, ClickHdl_Impl, CheckBox*, pCheckBox )
1714 {
1715     if ( ! _pFileNotifier )
1716         return 0;
1717 
1718     sal_Int16 nId = -1;
1719 
1720     if ( pCheckBox == _pImp->_pCbOptions )
1721         nId = CHECKBOX_FILTEROPTIONS;
1722     else if ( pCheckBox == _pCbSelection )
1723         nId = CHECKBOX_SELECTION;
1724     else if ( pCheckBox == _pCbReadOnly )
1725         nId = CHECKBOX_READONLY;
1726     else if ( pCheckBox == _pImp->_pCbPassword )
1727         nId = CHECKBOX_PASSWORD;
1728     else if ( pCheckBox == _pCbLinkBox )
1729         nId = CHECKBOX_LINK;
1730     else if ( pCheckBox == _pCbPreviewBox )
1731         nId = CHECKBOX_PREVIEW;
1732 
1733 	if ( nId != -1 )
1734         _pFileNotifier->notify( CTRL_STATE_CHANGED, nId );
1735 
1736     return 0;
1737 }
1738 
1739 //*****************************************************************************
1740 
1741 IMPL_LINK( SvtFileDialog, PlayButtonHdl_Impl, PushButton*, EMPTYARG )
1742 {
1743     if ( _pFileNotifier )
1744         _pFileNotifier->notify( CTRL_STATE_CHANGED,
1745                                 PUSHBUTTON_PLAY );
1746 
1747     return 0;
1748 }
1749 
1750 //*****************************************************************************
1751 
1752 long SvtFileDialog::Notify( NotifyEvent& rNEvt )
1753 
1754 /*	[Beschreibung]
1755 
1756 	Die Methode wird gerufen, <BACKSPACE> abzufangen.
1757 */
1758 
1759 {
1760 	sal_uInt16 nType = rNEvt.GetType();
1761 	long nRet = 0;
1762 
1763 	if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
1764 	{
1765 		const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1766 		sal_uInt16 nCode = rKeyCode.GetCode();
1767 
1768 		if ( !rKeyCode.GetModifier() &&
1769 			 KEY_BACKSPACE == nCode && !_pImp->_pEdFileName->HasChildPathFocus() )
1770 		{
1771 			nRet = 0; //! (long)_pFileView->DoBeamerKeyInput( *rNEvt.GetKeyEvent() );
1772 
1773 			if ( !nRet && _pImp->_pBtnUp->IsEnabled() )
1774 			{
1775 				PrevLevel_Impl();
1776 				nRet = 1;
1777 			}
1778 		}
1779 //		else if ( rKeyCode.IsMod1() && ( KEY_C == nCode || KEY_V == nCode || KEY_X == nCode ) )
1780 //		{
1781 /* (mhu)
1782 			String aVerb = KEY_C == nCode ? UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_COPY)) :
1783 				( KEY_V == nCode ? UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_PASTE)) : UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_CUT)) );
1784 //(dv)			if ( !CntPopupMenu::DoVerbCommand( aVerb, _pFileView->GetView() ) )
1785 //(dv)				Sound::Beep();
1786 */
1787 //		}
1788 	}
1789 	return nRet ? nRet : ModalDialog::Notify( rNEvt );
1790 }
1791 
1792 //*****************************************************************************
1793 
1794 long SvtFileDialog::OK()
1795 {
1796 	return sal_True;
1797 }
1798 
1799 //*****************************************************************************
1800 
1801 class SvtDefModalDialogParent_Impl
1802 {
1803 private:
1804 	Window*	_pOld;
1805 
1806 public:
1807 	SvtDefModalDialogParent_Impl( Window *pNew ) :
1808 		_pOld( Application::GetDefDialogParent() )
1809 		{ Application::SetDefDialogParent( pNew ); }
1810 
1811 	~SvtDefModalDialogParent_Impl() { Application::SetDefDialogParent( _pOld ); }
1812 };
1813 
1814 //*****************************************************************************
1815 
1816 //---------------------------------------------------------------------
1817 void SvtFileDialog::updateListboxLabelSizes()
1818 {
1819     sal_Int16 nLineControlId[5] = {
1820         LISTBOX_VERSION, LISTBOX_TEMPLATE, LISTBOX_IMAGE_TEMPLATE, LISTBOX_FILTER, EDIT_FILEURL
1821     };
1822 
1823     // determine the maximum width needed for the listbox labels
1824     long nMaxWidth = 0;
1825     for ( sal_Int32 i=0; i<5; ++i )
1826     {
1827         FixedText* pLabel = static_cast< FixedText* >( getControl( nLineControlId[i], sal_True ) );
1828         if ( !pLabel )
1829             continue;
1830         nMaxWidth = ::std::max( pLabel->GetTextWidth( pLabel->GetText() ), nMaxWidth );
1831     }
1832 
1833     // ensure that all labels are wide enough
1834     for ( sal_Int32 i=0; i<5; ++i )
1835     {
1836         FixedText* pLabel = static_cast< FixedText* >( getControl( nLineControlId[i], sal_True ) );
1837         ListBox* pListbox = static_cast< ListBox* >( getControl( nLineControlId[i], sal_False ) );
1838         if ( !pLabel || !pListbox )
1839             continue;
1840         Size aCurrentSize( pLabel->GetSizePixel() );
1841         if ( aCurrentSize.Width() >= nMaxWidth )
1842             continue;
1843 
1844         long nChange = nMaxWidth - aCurrentSize.Width();
1845         pLabel->SetSizePixel( Size( nMaxWidth, aCurrentSize.Height() ) );
1846 
1847         aCurrentSize = pListbox->GetSizePixel();
1848         pListbox->SetSizePixel( Size( aCurrentSize.Width() - nChange, aCurrentSize.Height() ) );
1849         lcl_MoveControl( pListbox, nChange, 0 );
1850     }
1851 }
1852 
1853 namespace
1854 {
1855 
1856 bool implIsInvalid( const String & rURL )
1857 {
1858 	SmartContent aContent( rURL );
1859 	aContent.enableOwnInteractionHandler( ::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST );
1860 	aContent.isFolder();	// do this _before_ asking isInvalid! Otherwise result might be wrong.
1861 	return aContent.isInvalid();
1862 }
1863 
1864 }
1865 
1866 //---------------------------------------------------------------------
1867 String SvtFileDialog::implGetInitialURL( const String& _rPath, const String& _rFallback )
1868 {
1869 	// an URL parser for the fallback
1870 	INetURLObject aURLParser;
1871 
1872 	// set the path
1873 	bool bWasAbsolute = sal_False;
1874 	aURLParser = aURLParser.smartRel2Abs( _rPath, bWasAbsolute );
1875 
1876 	// is it a valid folder?
1877 	m_aContent.bindTo( aURLParser.GetMainURL( INetURLObject::NO_DECODE ) );
1878 	sal_Bool bIsFolder = m_aContent.isFolder( );	// do this _before_ asking isInvalid!
1879 	sal_Bool bIsInvalid = m_aContent.isInvalid();
1880 
1881 	if ( bIsInvalid && m_bHasFilename && !aURLParser.hasFinalSlash() )
1882 	{	// check if the parent folder exists
1883 		// #108429# - 2003-03-26 - fs@openoffice.org
1884 		INetURLObject aParent( aURLParser );
1885 		aParent.removeSegment( );
1886 		aParent.setFinalSlash( );
1887 		bIsInvalid = implIsInvalid( aParent.GetMainURL( INetURLObject::NO_DECODE ) );
1888 	}
1889 
1890 	if ( bIsInvalid )
1891 	{
1892 		INetURLObject aFallback( _rFallback );
1893 		bIsInvalid = implIsInvalid( aFallback.GetMainURL( INetURLObject::NO_DECODE ) );
1894 
1895 	    if ( !bIsInvalid )
1896 			aURLParser = aFallback;
1897 	}
1898 
1899     if ( bIsInvalid )
1900 	{
1901 		INetURLObject aParent( aURLParser );
1902 		while ( bIsInvalid && aParent.removeSegment() )
1903 		{
1904 			aParent.setFinalSlash( );
1905 			bIsInvalid = implIsInvalid( aParent.GetMainURL( INetURLObject::NO_DECODE ) );
1906 		}
1907 
1908 	    if ( !bIsInvalid )
1909 			aURLParser = aParent;
1910 	}
1911 
1912 	if ( !bIsInvalid && bIsFolder )
1913 	{
1914 		aURLParser.setFinalSlash();
1915 	}
1916 	return aURLParser.GetMainURL( INetURLObject::NO_DECODE );
1917 }
1918 
1919 //---------------------------------------------------------------------
1920 short SvtFileDialog::Execute()
1921 {
1922     if ( !PrepareExecute() )
1923         return 0;
1924 
1925 	// Start des Dialogs.
1926     _bIsInExecute = sal_True;
1927 	short nResult = ModalDialog::Execute();
1928     _bIsInExecute = sal_False;
1929 
1930     DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFilePicker::Execute: still running an async action!" );
1931         // the dialog should not be cancellable while an async action is running - firs, the action
1932         // needs to be cancelled
1933 
1934 	// letztes Verzeichnis merken
1935 	if ( RET_OK == nResult )
1936 	{
1937 		INetURLObject aURL( _aPath );
1938 		if ( aURL.GetProtocol() == INET_PROT_FILE )
1939 		{
1940 			// nur bei File-URL's und nicht bei virtuelle Folder
1941 			// das ausgew"ahlte Verzeichnis merken
1942 			sal_Int32 nLevel = aURL.getSegmentCount();
1943 			// #97148# & #102204# ------
1944 			sal_Bool bDir = m_aContent.isFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1945             // sal_Bool bClassPath = ( ( _pImp->_nStyle & SFXWB_CLASSPATH ) == SFXWB_CLASSPATH );
1946 			if ( nLevel > 1 && ( FILEDLG_TYPE_FILEDLG == _pImp->_eDlgType || !bDir ) )
1947 				aURL.removeSegment();
1948 		}
1949 	}
1950 
1951     return nResult;
1952 }
1953 
1954 //---------------------------------------------------------------------
1955 void SvtFileDialog::StartExecuteModal( const Link& rEndDialogHdl )
1956 {
1957     PrepareExecute();
1958 
1959     // Start des Dialogs.
1960 //    _bIsInExecute = sal_True;
1961     ModalDialog::StartExecuteModal( rEndDialogHdl );
1962 }
1963 
1964 //-----------------------------------------------------------------------------
1965 void SvtFileDialog::onAsyncOperationStarted()
1966 {
1967     EnableUI( sal_False );
1968     // the cancel button must be always enabled
1969     _pImp->_pBtnCancel->Enable( sal_True );
1970     _pImp->_pBtnCancel->GrabFocus();
1971 }
1972 
1973 //-----------------------------------------------------------------------------
1974 void SvtFileDialog::onAsyncOperationFinished()
1975 {
1976     EnableUI( sal_True );
1977     m_pCurrentAsyncAction = NULL;
1978     if ( !m_bInExecuteAsync )
1979         _pImp->_pEdFileName->GrabFocus();
1980         // (if m_bInExecuteAsync is true, then the operation was finished within the minium wait time,
1981         // and to the user, the operation appears to be synchronous)
1982 }
1983 
1984 //-------------------------------------------------------------------------
1985 void SvtFileDialog::displayIOException( const String& _rURL, IOErrorCode _eCode )
1986 {
1987     try
1988     {
1989         // create make a human-readable string from the URL
1990         String sDisplayPath( _rURL );
1991         ::utl::LocalFileHelper::ConvertURLToSystemPath( _rURL, sDisplayPath );
1992 
1993         // build an own exception which tells "access denied"
1994         InteractiveAugmentedIOException aException;
1995         aException.Arguments.realloc( 2 );
1996         aException.Arguments[ 0 ] <<= ::rtl::OUString( sDisplayPath );
1997         aException.Arguments[ 1 ] <<= PropertyValue(
1998             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ),
1999             -1, aException.Arguments[ 0 ], PropertyState_DIRECT_VALUE
2000         );
2001             // (formerly, it was sufficient to put the URL first parameter. Nowadays,
2002             // the services expects the URL in a PropertyValue named "Uri" ...)
2003         aException.Code = _eCode;
2004         aException.Classification = InteractionClassification_ERROR;
2005 
2006         // let and interaction handler handle this exception
2007         ::comphelper::OInteractionRequest* pRequest = NULL;
2008         Reference< ::com::sun::star::task::XInteractionRequest > xRequest = pRequest =
2009             new ::comphelper::OInteractionRequest( makeAny( aException ) );
2010         pRequest->addContinuation( new ::comphelper::OInteractionAbort( ) );
2011 
2012         Reference< XInteractionHandler > xHandler(
2013             ::comphelper::getProcessServiceFactory()->createInstance(
2014                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") )
2015             ),
2016             UNO_QUERY
2017         );
2018         if ( xHandler.is() )
2019             xHandler->handle( xRequest );
2020     }
2021     catch( const Exception& )
2022     {
2023         DBG_ERROR( "iodlg::displayIOException: caught an exception!" );
2024     }
2025 }
2026 
2027 //-----------------------------------------------------------------------------
2028 void SvtFileDialog::EnableUI( sal_Bool _bEnable )
2029 {
2030     Enable( _bEnable );
2031 
2032     if ( _bEnable )
2033     {
2034         for ( ::std::set< Control* >::iterator aLoop = m_aDisabledControls.begin();
2035               aLoop != m_aDisabledControls.end();
2036               ++aLoop
2037             )
2038         {
2039             (*aLoop)->Enable( sal_False );
2040         }
2041     }
2042 }
2043 
2044 //-----------------------------------------------------------------------------
2045 void SvtFileDialog::EnableControl( Control* _pControl, sal_Bool _bEnable )
2046 {
2047     if ( !_pControl )
2048     {
2049         DBG_ERRORFILE( "SvtFileDialog::EnableControl: invalid control!" );
2050         return;
2051     }
2052 
2053     _pControl->Enable( _bEnable );
2054 
2055     if ( _bEnable )
2056     {
2057         ::std::set< Control* >::iterator aPos = m_aDisabledControls.find( _pControl );
2058         if ( m_aDisabledControls.end() != aPos )
2059             m_aDisabledControls.erase( aPos );
2060     }
2061     else
2062         m_aDisabledControls.insert( _pControl );
2063 }
2064 
2065 //----------------------------------------------------------------------------
2066 
2067 short SvtFileDialog::PrepareExecute()
2068 {
2069     rtl::OUString aEnvValue;
2070     if ( getEnvironmentValue( "WorkDirMustContainRemovableMedia", aEnvValue ) &&
2071          aEnvValue.equalsAscii( "1" ) )
2072     {
2073         try
2074         {
2075             INetURLObject aStdDir( GetStandardDir() );
2076             ::ucbhelper::Content aCnt( rtl::OUString( aStdDir.GetMainURL(
2077                                                     INetURLObject::NO_DECODE ) ),
2078                                  Reference< XCommandEnvironment >() );
2079             Sequence< rtl::OUString > aProps(2);
2080             aProps[0] = rtl::OUString::createFromAscii( "IsVolume" );
2081             aProps[1] = rtl::OUString::createFromAscii( "IsRemoveable" );
2082 
2083             Reference< XResultSet > xResultSet
2084                 = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_ONLY );
2085             if ( xResultSet.is() )
2086             {
2087                 Reference< XRow > xRow( xResultSet, UNO_QUERY );
2088 
2089                 bool bEmpty = true;
2090                 if ( !xResultSet->next() )
2091                 {
2092                     // folder is empty
2093                     bEmpty = true;
2094                 }
2095                 else
2096                 {
2097 // @@@ KSO 05/18/2006: support for removable media currently hardcoded/incomplete in OSL
2098 //
2099 //                    do
2100 //                    {
2101 //                        // check, whether child is a removable volume
2102 //                        if ( xRow->getBoolean( 1 ) && !xRow->wasNull() )
2103 //                        {
2104 //                            if ( xRow->getBoolean( 2 ) && !xRow->wasNull() )
2105 //                            {
2106                                 bEmpty = false;
2107 //                                break;
2108 //                            }
2109 //                        }
2110 //                    }
2111 //                    while ( xResultSet->next() );
2112                 }
2113 
2114                 if ( bEmpty )
2115                 {
2116                     ErrorBox aBox( this, WB_OK, SvtResId( STR_SVT_NOREMOVABLEDEVICE ) );
2117                     aBox.Execute();
2118                     return 0;
2119                 }
2120             }
2121         }
2122         catch ( ContentCreationException const & )
2123         {
2124         }
2125         catch ( CommandAbortedException const & )
2126         {
2127         }
2128     }
2129 
2130     // #102204# ---------------
2131 	if ( ( _pImp->_nStyle & WB_SAVEAS ) && m_bHasFilename )
2132 		// when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2133 		// - finally we're going to save that file, aren't we?
2134 		// #105812# - 2002-12-02 - fs@openoffice.org
2135         m_aContent.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST);
2136     else
2137         m_aContent.enableDefaultInteractionHandler();
2138 
2139 	// #53016# evtl. nur ein Filename ohne Pfad?
2140 	String aFileNameOnly;
2141 	if( _aPath.Len() && (_pImp->_eMode == FILEDLG_MODE_SAVE)
2142 					 && (_aPath.Search(':') == STRING_NOTFOUND)
2143 					 && (_aPath.Search('\\') == STRING_NOTFOUND)
2144 					 && (_aPath.Search('/') == STRING_NOTFOUND))
2145 	{
2146 		aFileNameOnly = _aPath;
2147 		_aPath.Erase();
2148 	}
2149 
2150 	// kein Startpfad angegeben?
2151 	if ( !_aPath.Len() )
2152 	{
2153 		// dann das Standard-Dir verwenden
2154 		_aPath = lcl_ensureFinalSlash( _pImp->GetStandardDir() );
2155 
2156 		// #53016# vorgegebener Dateiname an Pfad anh"angen
2157 		if ( aFileNameOnly.Len() )
2158 			_aPath += aFileNameOnly;
2159 	}
2160 
2161 	//.....................................................................
2162 	_aPath = implGetInitialURL( _aPath, GetStandardDir() );
2163 
2164 	if ( _pImp->_nStyle & WB_SAVEAS && !m_bHasFilename )
2165 		// when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2166 		// - finally we're going to save that file, aren't we?
2167         m_aContent.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST);
2168 
2169 	//.....................................................................
2170 	// care for possible restrictions on the paths we're allowed to show
2171     if ( !m_aURLFilter.isUrlAllowed( _aPath ) )
2172         _aPath = m_aURLFilter.getFilter()[0];
2173 
2174 	// Ggf. Filter anzeigen.
2175 	_pImp->InitFilterList();
2176 
2177 	// Initialen Filter einstellen.
2178 	sal_uInt16 nFilterCount = GetFilterCount();
2179 	String aAll( SvtResId( STR_FILTERNAME_ALL ) );
2180 	sal_Bool bHasAll = _pImp->HasFilterListEntry( aAll );
2181 	if ( _pImp->GetCurFilter() || nFilterCount == 1 || ( nFilterCount == 2 && bHasAll ) )
2182 	{
2183 		// Ggf. einzigen Filter als aktuellen Filter setzen oder den einzigen
2184 		// Filter, der nicht auf alle Dateien verweist.
2185 		if ( !_pImp->GetCurFilter() )
2186 		{
2187 			sal_uInt16 nPos = 0;
2188 			if ( 2 == nFilterCount && bHasAll )
2189 			{
2190 				nPos = nFilterCount;
2191 				while ( nPos-- )
2192 				{
2193 					if ( GetFilterName( nPos ) != aAll )
2194 						break;
2195 				}
2196 			}
2197 			SvtFileDialogFilter_Impl* pNewCurFilter = _pImp->_pFilter->GetObject( nPos );
2198 			DBG_ASSERT( pNewCurFilter, "SvtFileDialog::Execute: invalid filter pos!" );
2199 			_pImp->SetCurFilter( pNewCurFilter, pNewCurFilter->GetName() );
2200 		}
2201 
2202 		// Anzeige anpassen.
2203 		_pImp->SelectFilterListEntry( _pImp->GetCurFilter()->GetName() );
2204         SetDefaultExt( _pImp->GetCurFilter()->GetExtension() );
2205 		sal_uInt16 nSepPos = GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP );
2206 		if ( nSepPos != STRING_NOTFOUND )
2207 			EraseDefaultExt( nSepPos );
2208 	}
2209 	else
2210 	{
2211 		// Ggf. Filter fuer alle Dateien setzen bzw. erzeugen.
2212 		if ( !bHasAll )
2213 		{
2214 			SvtFileDialogFilter_Impl* pAllFilter = implAddFilter( aAll, UniString(RTL_CONSTASCII_USTRINGPARAM(FILEDIALOG_FILTER_ALL)) );
2215 			_pImp->InsertFilterListEntry( pAllFilter );
2216 			_pImp->SetCurFilter( pAllFilter, aAll );
2217 		}
2218 		_pImp->SelectFilterListEntry( aAll );
2219 	}
2220 
2221 	_pImp->_pDefaultFilter = _pImp->GetCurFilter();
2222 
2223 	// HACK #50065#
2224 	// ggf. Filter isolieren.
2225 	String aFilter;
2226 
2227 	if ( !IsolateFilterFromPath_Impl( _aPath, aFilter ) )
2228 		return 0;
2229 
2230 	sal_uInt16 nNewFilterFlags = adjustFilter( aFilter );
2231 	if ( nNewFilterFlags & ( FLT_NONEMPTY | FLT_USERFILTER ) )
2232 	{
2233 		_pImp->_pEdFileName->SetText( aFilter );
2234 	}
2235 	// HACK #50065#
2236 
2237 	// Instanz fuer den gesetzten Pfad erzeugen und anzeigen.
2238 	INetURLObject aFolderURL( _aPath );
2239 	String aFileName( aFolderURL.getName( INetURLObject::LAST_SEGMENT, false ) );
2240 	xub_StrLen nFileNameLen = aFileName.Len();
2241 	bool bFileToSelect = nFileNameLen != 0;
2242 	if ( bFileToSelect && aFileName.GetChar( nFileNameLen - 1 ) != INET_PATH_TOKEN )
2243 	{
2244 		_pImp->_pEdFileName->SetText( GET_DECODED_NAME( aFolderURL ) );
2245 		aFolderURL.removeSegment();
2246 	}
2247 
2248 	INetURLObject aObj = aFolderURL;
2249 	if ( aObj.GetProtocol() == INET_PROT_FILE )
2250 	{
2251 		// Ordner als aktuelles Verzeichnis setzen.
2252 		aObj.setFinalSlash();
2253 	}
2254 
2255 	UpdateControls( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2256 
2257     // Somebody might want to enable some controls acording to the current filter
2258     FilterSelect();
2259 
2260 	// Zustand der Steuerelemente anpassen.
2261 //	EndListeningAll();
2262 
2263     ViewHdl_Impl( this, NULL );
2264     OpenURL_Impl( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2265 
2266 	_pFileView->Show();
2267 	SvtDefModalDialogParent_Impl aDefParent( this );
2268 
2269 	// ggf. Gr"osse aus Ini lesen und setzen
2270 	InitSize();
2271 
2272     return 1;
2273 }
2274 
2275 //-----------------------------------------------------------------------------
2276 void SvtFileDialog::implInitializeSpecialURLLists( )
2277 {
2278     m_aURLFilter = ::svt::RestrictedPaths();
2279 
2280     ::std::vector< String > aFavourites;
2281     if ( m_aURLFilter.hasFilter() )
2282     {
2283         // if we have restrictions, then the "favourites" are the restricted folders only
2284         aFavourites = m_aURLFilter.getFilter();
2285         // for approved URLs, we needed the final slashes, for
2286         // favourites, we do not want to have them
2287         ::std::for_each( aFavourites.begin(), aFavourites.end(), RemoveFinalSlash() );
2288     }
2289     else
2290     {
2291         ::rtl::OUString sFavouritesList;
2292         if ( getEnvironmentValue( "PathFavourites", sFavouritesList ) )
2293             convertStringListToUrls( sFavouritesList, aFavourites, false );
2294     }
2295 
2296     DBG_ASSERT( _pImp->_pBtnStandard, "SvtFileDialog::implInitializeSpecialURLLists: how this?" );
2297     if ( _pImp->_pBtnStandard )
2298         _pImp->_pBtnStandard->SetFavouriteLocations( aFavourites );
2299 }
2300 
2301 //-----------------------------------------------------------------------------
2302 void SvtFileDialog::executeAsync( ::svt::AsyncPickerAction::Action _eAction,
2303                                     const String& _rURL, const String& _rFilter )
2304 {
2305     DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );
2306 
2307     m_pCurrentAsyncAction = new AsyncPickerAction( this, _pFileView, _eAction );
2308 
2309     bool bReallyAsync = true;
2310     m_aConfiguration.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillAsynchronously" ) ) ) >>= bReallyAsync;
2311 
2312     sal_Int32 nMinTimeout = 0;
2313     m_aConfiguration.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Timeout/Min" ) ) ) >>= nMinTimeout;
2314     sal_Int32 nMaxTimeout = 0;
2315     m_aConfiguration.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Timeout/Max" ) ) ) >>= nMaxTimeout;
2316 
2317     m_bInExecuteAsync = true;
2318     m_pCurrentAsyncAction->execute( _rURL, _rFilter, bReallyAsync ? nMinTimeout : -1, nMaxTimeout, GetBlackList() );
2319     m_bInExecuteAsync = false;
2320 }
2321 
2322 //*****************************************************************************
2323 
2324 void SvtFileDialog::FileSelect()
2325 {
2326 	if ( _pFileNotifier )
2327 		_pFileNotifier->notify( FILE_SELECTION_CHANGED, 0 );
2328 }
2329 
2330 //*****************************************************************************
2331 
2332 void SvtFileDialog::FilterSelect()
2333 {
2334 	if ( _pFileNotifier )
2335 		_pFileNotifier->notify( CTRL_STATE_CHANGED,
2336                                 LISTBOX_FILTER );
2337 }
2338 
2339 //*****************************************************************************
2340 
2341 void SvtFileDialog::SetStandardDir( const String& rStdDir )
2342 
2343 /*	[Beschreibung]
2344 
2345 	Die Methode setzt den Pfad f"ur den Standardknopf.
2346 */
2347 
2348 {
2349     INetURLObject aObj( rStdDir );
2350     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid protocol!" );
2351 	aObj.setFinalSlash();
2352 	_pImp->SetStandardDir( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
2353 }
2354 
2355 void SvtFileDialog::SetBlackList( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
2356 {
2357 	_pImp->SetBlackList( rBlackList );
2358 }
2359 
2360 //*****************************************************************************
2361 
2362 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& SvtFileDialog::GetBlackList() const
2363 {
2364 	return _pImp->GetBlackList();
2365 }
2366 //*****************************************************************************
2367 
2368 const String& SvtFileDialog::GetStandardDir() const
2369 
2370 /*	[Beschreibung]
2371 
2372 	Diese Methode gibt den eingestellten Standardpfad zur"uck.
2373 */
2374 
2375 {
2376 	return _pImp->GetStandardDir();
2377 }
2378 
2379 //*****************************************************************************
2380 
2381 void SvtFileDialog::PrevLevel_Impl()
2382 {
2383     _pFileView->EndInplaceEditing( false );
2384 
2385     String sDummy;
2386     executeAsync( AsyncPickerAction::ePrevLevel, sDummy, sDummy );
2387 }
2388 
2389 //*****************************************************************************
2390 
2391 void SvtFileDialog::OpenURL_Impl( const String& _rURL )
2392 {
2393     _pFileView->EndInplaceEditing( false );
2394 
2395     DBG_ASSERT( m_aURLFilter.isUrlAllowed( _rURL ), "SvtFileDialog::OpenURL_Impl: forbidden URL! Should have been handled by the caller!" );
2396     executeAsync( AsyncPickerAction::eOpenURL, _rURL, getMostCurrentFilter( _pImp ) );
2397 }
2398 
2399 //*****************************************************************************
2400 SvtFileDialogFilter_Impl* SvtFileDialog::implAddFilter( const String& _rFilter, const String& _rType )
2401 {
2402 	SvtFileDialogFilter_Impl* pNewFilter = new SvtFileDialogFilter_Impl( _rFilter, _rType );
2403 	_pImp->_pFilter->C40_INSERT( SvtFileDialogFilter_Impl, pNewFilter, (sal_uInt16)0 );
2404 
2405 	if ( !_pImp->GetCurFilter() )
2406 		_pImp->SetCurFilter( pNewFilter, _rFilter );
2407 
2408 	return pNewFilter;
2409 }
2410 
2411 //*****************************************************************************
2412 
2413 void SvtFileDialog::AddFilter( const String& _rFilter, const String& _rType )
2414 {
2415 	DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2416 	implAddFilter ( _rFilter, _rType );
2417 }
2418 
2419 //*****************************************************************************
2420 void SvtFileDialog::AddFilterGroup( const String& _rFilter, const Sequence< StringPair >& _rFilters )
2421 {
2422 	DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2423 
2424 	implAddFilter( _rFilter, String() );
2425 	const StringPair* pSubFilters		=				_rFilters.getConstArray();
2426 	const StringPair* pSubFiltersEnd	= pSubFilters +	_rFilters.getLength();
2427 	for ( ; pSubFilters != pSubFiltersEnd; ++pSubFilters )
2428 		implAddFilter( pSubFilters->First, pSubFilters->Second );
2429 }
2430 
2431 //*****************************************************************************
2432 
2433 //-----------------------------------------------------------------------------
2434 void SvtFileDialog::SetCurFilter( const String& rFilter )
2435 {
2436 	DBG_ASSERT( !IsInExecute(), "SvtFileDialog::SetCurFilter: currently executing!" );
2437 
2438 	// Entsprechenden Filter suchen.
2439 	sal_uInt16 nPos = _pImp->_pFilter->Count();
2440 
2441     while ( nPos-- )
2442 	{
2443 		SvtFileDialogFilter_Impl* pFilter = _pImp->_pFilter->GetObject( nPos );
2444 		if ( pFilter->GetName() == rFilter )
2445 		{
2446 			_pImp->SetCurFilter( pFilter, rFilter );
2447 			break;
2448 		}
2449 	}
2450 }
2451 
2452 //*****************************************************************************
2453 
2454 String SvtFileDialog::GetCurFilter() const
2455 {
2456 	String aFilter;
2457 
2458 	const SvtFileDialogFilter_Impl* pCurrentFilter = _pImp->GetCurFilter();
2459     if ( pCurrentFilter )
2460 		aFilter = pCurrentFilter->GetName();
2461 
2462     return aFilter;
2463 }
2464 
2465 String SvtFileDialog::getCurFilter( ) const
2466 {
2467 	return GetCurFilter();
2468 }
2469 
2470 //*****************************************************************************
2471 
2472 sal_uInt16 SvtFileDialog::GetFilterCount() const
2473 {
2474 	return _pImp->_pFilter->Count();
2475 }
2476 
2477 //*****************************************************************************
2478 
2479 const String& SvtFileDialog::GetFilterName( sal_uInt16 nPos ) const
2480 {
2481 	DBG_ASSERT( nPos < GetFilterCount(), "invalid index" );
2482 	return _pImp->_pFilter->GetObject( nPos )->GetName();
2483 }
2484 
2485 //*****************************************************************************
2486 
2487 void SvtFileDialog::InitSize()
2488 {
2489 	if ( ! _pImp->_aIniKey.Len() )
2490         return;
2491 
2492 	Size aDlgSize = GetResizeOutputSizePixel();
2493 	SetMinOutputSizePixel( aDlgSize );
2494 
2495 	if ( !_pImp->_nFixDeltaHeight )
2496 	{
2497 		// Fixgr"ossen errechnen und merken
2498 		Point aPnt = _pFileView->GetPosPixel();
2499 		long nBoxH = _pFileView->GetSizePixel().Height();
2500 		long nH = GetSizePixel().Height();
2501 		_pImp->_nFixDeltaHeight = nH - nBoxH;
2502 	}
2503 
2504 	// initialize from config
2505 	SvtViewOptions aDlgOpt( E_DIALOG, _pImp->_aIniKey );
2506 
2507 	if ( aDlgOpt.Exists() )
2508 	{
2509 		SetWindowState( ByteString( String( aDlgOpt.GetWindowState() ), osl_getThreadTextEncoding() ) );
2510 
2511 		Any aUserData = aDlgOpt.GetUserItem( ::rtl::OUString::createFromAscii( "UserData" ) );
2512 		::rtl::OUString sCfgStr;
2513 		if ( aUserData >>= sCfgStr )
2514 			_pFileView->SetConfigString( String( sCfgStr ) );
2515 	}
2516 }
2517 
2518 //*****************************************************************************
2519 
2520 SvStringsDtor* SvtFileDialog::GetPathList() const
2521 {
2522 	SvStringsDtor*	pList = new SvStringsDtor;
2523 	sal_uLong			nCount = _pFileView->GetSelectionCount();
2524 	SvLBoxEntry*	pEntry = nCount ? _pFileView->FirstSelected() : NULL;
2525 
2526 	if ( ! pEntry )
2527 	{
2528 		String* pURL;
2529 
2530         if ( _pImp->_pEdFileName->GetText().Len() && _bIsInExecute )
2531             pURL = new String( _pImp->_pEdFileName->GetURL() );
2532         else
2533             pURL = new String( _aPath );
2534 
2535         pList->Insert( pURL, pList->Count() );
2536 	}
2537 	else
2538 	{
2539 		while ( pEntry )
2540 		{
2541 			String* pURL = new String( _pFileView->GetURL( pEntry ) );
2542 			pList->Insert( pURL, pList->Count() );
2543 			pEntry = _pFileView->NextSelected( pEntry );
2544 		}
2545 	}
2546 
2547 	return pList;
2548 }
2549 
2550 //*****************************************************************************
2551 
2552 void SvtFileDialog::implArrangeControls()
2553 {
2554     // this is the list of controls in the order they should be tabbed
2555     // from topleft to bottomright
2556     // pb: #136070# new order so all LabeledBy relations are correct now
2557     Control* pControls[] =
2558     {
2559         _pImp->_pFtCurrentPath,
2560         _pImp->_pBtnUp, _pImp->_pBtnNewFolder, _pImp->_pBtnStandard,        // image buttons
2561         _pFileView,                                                         // the file view
2562         _pImp->_pFtFileName, _pImp->_pEdFileName,
2563         _pImp->_pFtFileVersion, _pImp->_pLbFileVersion,
2564         _pImp->_pFtTemplates, _pImp->_pLbTemplates,
2565         _pImp->_pFtImageTemplates, _pImp->_pLbImageTemplates,
2566         _pImp->_pFtFileType, _pImp->GetFilterListControl(),                 // edit fields/list boxes
2567         _pImp->_pCbPassword, _pImp->_pCbAutoExtension, _pImp->_pCbOptions,  // checkboxes
2568         _pCbReadOnly, _pCbLinkBox, _pCbPreviewBox, _pCbSelection, _pPbPlay, // check boxes (continued)
2569         _pImp->_pBtnFileOpen, _pImp->_pBtnCancel, _pImp->_pBtnHelp          // buttons
2570 
2571         // (including the FixedTexts is important - not for tabbing order (they're irrelevant there),
2572         // but for working keyboard shortcuts)
2573         // 96861 - 23.01.2002 - fs@openoffice.org
2574     };
2575 
2576     // loop through all these controls and adjust the z-order
2577     Window* pPreviousWin = NULL;
2578     Control** pCurrent = pControls;
2579     for ( sal_Int32 i = 0; i < sal_Int32(sizeof( pControls ) / sizeof( pControls[ 0 ] )); ++i, ++pCurrent )
2580     {
2581         if ( !*pCurrent )
2582             // this control is not available in the current operation mode -> skip
2583             continue;
2584 
2585         if ( pPreviousWin )
2586             (*pCurrent)->SetZOrder( pPreviousWin, WINDOW_ZORDER_BEHIND );
2587         else
2588             (*pCurrent)->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
2589 
2590         pPreviousWin = *pCurrent;
2591     }
2592 
2593     // FileName edit not the first control but it should have the focus initially
2594     _pImp->_pEdFileName->GrabFocus();
2595 }
2596 
2597 //*****************************************************************************
2598 
2599 sal_Bool SvtFileDialog::IsolateFilterFromPath_Impl( String& rPath, String& rFilter )
2600 {
2601 	String aEmpty;
2602 	String aReversePath( rPath );
2603 	aReversePath.Reverse();
2604 	sal_uInt16 nQuestionMarkPos = rPath.Search( '?' );
2605 
2606 	if ( nQuestionMarkPos != STRING_NOTFOUND )
2607 	{
2608 		// Fragezeichen als Wildcard nur bei Files
2609 		INetProtocol eProt = INetURLObject::CompareProtocolScheme( rPath );
2610 
2611 		if ( INET_PROT_NOT_VALID != eProt && INET_PROT_FILE != eProt )
2612 			nQuestionMarkPos = STRING_NOTFOUND;
2613 	}
2614 	sal_uInt16 nWildCardPos = Min( rPath.Search( FILEDIALOG_DEF_WILDCARD ), nQuestionMarkPos );
2615 	rFilter = aEmpty;
2616 
2617 	if ( nWildCardPos != STRING_NOTFOUND )
2618 	{
2619 		sal_uInt16 nPathTokenPos = aReversePath.Search( INET_PATH_TOKEN );
2620 
2621 		if ( nPathTokenPos == STRING_NOTFOUND )
2622 		{
2623 			String aDelim(
2624 #if defined(WNT) || defined(OS2)
2625 					'\\'
2626 #else
2627 					'/'
2628 #endif
2629 			);
2630 
2631 			nPathTokenPos = aReversePath.Search( aDelim );
2632 #if defined(OS2)
2633 			if ( nPathTokenPos == STRING_NOTFOUND )
2634 			{
2635 				nPathTokenPos = aReversePath.Search( '/' );
2636 			}
2637 #endif
2638 #if !defined( UNX )
2639 			if ( nPathTokenPos == STRING_NOTFOUND )
2640 			{
2641 				nPathTokenPos = aReversePath.Search( ':' );
2642 			}
2643 #endif
2644 		}
2645 
2646 		// Syntax pr"ufen.
2647 		if ( nPathTokenPos != STRING_NOTFOUND )
2648 		{
2649 			if ( nPathTokenPos < (rPath.Len() - nWildCardPos - 1) )
2650 			{
2651 				ErrorHandler::HandleError( ERRCODE_SFX_INVALIDSYNTAX );
2652 				return sal_False;
2653 			}
2654 
2655 			// Filter abschneiden.
2656 			rFilter = aReversePath;
2657 			rFilter.Erase( nPathTokenPos );
2658 			rFilter.Reverse();
2659 
2660 			// Ordner bestimmen.
2661 			rPath = aReversePath;
2662 			rPath.Erase( 0, nPathTokenPos );
2663 			rPath.Reverse();
2664 		}
2665 		else
2666 		{
2667 			rFilter = rPath;
2668 			rPath = aEmpty;
2669 		}
2670 	}
2671 
2672 	return sal_True;
2673 }
2674 
2675 //*****************************************************************************
2676 
2677 //-----------------------------------------------------------------------------
2678 void SvtFileDialog::implUpdateImages( )
2679 {
2680 	// determine high contrast mode
2681 	{
2682 		sal_Bool bIsHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
2683 		m_aImages = ImageList( SvtResId( bIsHighContrast ? RID_FILEPICKER_IMAGES_HC : RID_FILEPICKER_IMAGES ) );
2684 	}
2685 
2686 	// set the appropriate images on the buttons
2687 	if ( _pImp->_pBtnUp )
2688 		_pImp->_pBtnUp->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_UP ) );
2689 
2690 	if ( _pImp->_pBtnStandard )
2691 		_pImp->_pBtnStandard->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_STD ) );
2692 
2693 	if ( _pImp->_pBtnNewFolder )
2694 		_pImp->_pBtnNewFolder->SetModeImage( GetButtonImage( IMG_FILEDLG_CREATEFOLDER ) );
2695 }
2696 
2697 //-----------------------------------------------------------------------------
2698 void SvtFileDialog::DataChanged( const DataChangedEvent& _rDCEvt )
2699 {
2700 	if ( DATACHANGED_SETTINGS == _rDCEvt.GetType() )
2701 		implUpdateImages( );
2702 
2703 	ModalDialog::DataChanged( _rDCEvt );
2704 }
2705 
2706 //-----------------------------------------------------------------------------
2707 void SvtFileDialog::Resize()
2708 {
2709 	if ( IsRollUp() )
2710 		return;
2711 
2712 	Size aDlgSize = GetResizeOutputSizePixel();
2713 	Size aOldSize = _pImp->_aDlgSize;
2714 	_pImp->_aDlgSize = aDlgSize;
2715 	long nWinDeltaW = 0;
2716 
2717 	if ( _pPrevWin &&
2718          _pPrevWin->GetPosPixel().X() > _pFileView->GetPosPixel().X() )
2719 	{
2720 		nWinDeltaW = _pPrevWin->GetOutputSizePixel().Width() + _pImp->_a6Size.Width();
2721 	}
2722 
2723 	Size aNewSize = _pFileView->GetSizePixel();
2724 	Point aBoxPos( _pFileView->GetPosPixel() );
2725 	long nDeltaY = aNewSize.Height();
2726 	long nDeltaX = aNewSize.Width();
2727 	aNewSize.Height() = aDlgSize.Height() - _pImp->_nFixDeltaHeight;
2728 	aNewSize.Width() = aDlgSize.Width() - aBoxPos.X() - _pImp->_a6Size.Width() - nWinDeltaW;
2729 	if ( aOldSize.Height() )
2730 		nDeltaY = _pImp->_aDlgSize.Height() - aOldSize.Height();
2731 	else
2732 		nDeltaY = aNewSize.Height() - nDeltaY;
2733 	nDeltaX = aNewSize.Width() - nDeltaX;
2734 
2735 	if ( nWinDeltaW )
2736 		nWinDeltaW = nDeltaX * 2 / 3;
2737 	aNewSize.Width() -= nWinDeltaW;
2738 	nDeltaX -= nWinDeltaW;
2739 
2740 	_pFileView->SetSizePixel( aNewSize );
2741 
2742 	if ( !nDeltaY && !nDeltaX )
2743 		// Dieses Resize wurde nur zum Ein - oder Ausblenden des Indicators aufgerufen
2744 		return;
2745 
2746 	// -------------
2747 	// move controls
2748 
2749 	// controls to move vertically
2750 	{
2751 		Control* aMoveControlsVert[] =
2752 		{
2753 			_pImp->_pFtFileName, _pImp->_pEdFileName, _pImp->_pFtFileVersion, _pImp->_pLbFileVersion,
2754 			_pImp->_pFtTemplates, _pImp->_pLbTemplates, _pImp->_pFtImageTemplates, _pImp->_pLbImageTemplates,
2755 			_pImp->_pFtFileType, _pImp->GetFilterListControl(), _pCbReadOnly, _pCbLinkBox, _pCbPreviewBox,
2756 			_pPbPlay, _pImp->_pCbPassword, _pImp->_pCbAutoExtension, _pImp->_pCbOptions, _pCbSelection
2757 		};
2758 		Control** ppMoveControls = aMoveControlsVert;
2759 		Control** ppMoveControlsEnd = ppMoveControls + sizeof( aMoveControlsVert ) / sizeof( aMoveControlsVert[0] );
2760 		for ( ; ppMoveControls != ppMoveControlsEnd; ++ppMoveControls )
2761 			lcl_MoveControl( *ppMoveControls, 0, nDeltaY );
2762 	}
2763 
2764 	// controls to move vertically and horizontally
2765 	{
2766 		Control* aMoveControlsBoth[] =
2767 		{
2768 			_pImp->_pBtnFileOpen, _pImp->_pBtnCancel, _pImp->_pBtnHelp
2769 		};
2770 		Control** ppMoveControls = aMoveControlsBoth;
2771 		Control** ppMoveControlsEnd = ppMoveControls + sizeof( aMoveControlsBoth ) / sizeof( aMoveControlsBoth[0] );
2772 		for ( ; ppMoveControls != ppMoveControlsEnd; ++ppMoveControls )
2773 			lcl_MoveControl( *ppMoveControls, nDeltaX, nDeltaY );
2774 	}
2775 
2776 	// controls to move horizontally
2777 	{
2778 		Control* aMoveControlsHor[] =
2779 		{
2780 			_pImp->_pBtnUp, _pImp->_pBtnNewFolder, _pImp->_pBtnStandard
2781 		};
2782 		Control** ppMoveControls = aMoveControlsHor;
2783 		Control** ppMoveControlsEnd = ppMoveControls + sizeof( aMoveControlsHor ) / sizeof( aMoveControlsHor[0] );
2784 		for ( ; ppMoveControls != ppMoveControlsEnd; ++ppMoveControls )
2785 			lcl_MoveControl( *ppMoveControls, nDeltaX, 0 );
2786 	}
2787 
2788 	// ---------------
2789 	// resize controls
2790 	{
2791 		Control* aSizeControls[] =
2792 		{
2793 			_pImp->_pEdFileName, _pImp->_pLbFileVersion, _pImp->_pLbTemplates, _pImp->_pLbImageTemplates,
2794 			_pImp->GetFilterListControl(), _pImp->_pFtCurrentPath,
2795 		};
2796 		sal_Int32 nSizeControls = sizeof( aSizeControls ) / sizeof( aSizeControls[0] );
2797 		Control** ppSizeControls = aSizeControls;
2798 		for ( sal_Int32 j=0; j<nSizeControls; ++j, ++ppSizeControls )
2799 		{
2800 			if ( *ppSizeControls )
2801 			{
2802 				aNewSize = (*ppSizeControls)->GetSizePixel();
2803 				aNewSize.Width() += nDeltaX;
2804 				(*ppSizeControls)->SetSizePixel( aNewSize );
2805 			}
2806 		}
2807 	}
2808 
2809 	// zus"atzliche Controls ausrichten
2810 	if ( _pPrevWin &&
2811          _pPrevWin->GetPosPixel().X() > _pFileView->GetPosPixel().X() )
2812 	{
2813 		// Controls vom Typ Window speziell ausrichten
2814 		// auch die Gr"osse anpassen
2815 		Point aNewPos = _pPrevWin->GetPosPixel();
2816 		aNewPos.X() += nDeltaX;
2817 		_pPrevWin->SetPosPixel( aNewPos );
2818         _pPrevBmp->SetPosPixel( aNewPos );
2819 		aNewSize = _pPrevWin->GetOutputSizePixel();
2820 		aNewSize.Width() += nWinDeltaW;
2821 		aNewSize.Height() += nDeltaY;
2822 		if ( !aOldSize.Height() )
2823 			aNewSize.Height() -= ( _pImp->_a6Size.Height() / 2 );
2824 		_pPrevWin->SetOutputSizePixel( aNewSize );
2825 		_pPrevBmp->SetOutputSizePixel( aNewSize );
2826         _pPrevBmp->Invalidate();
2827 	}
2828 
2829     if ( _pFileNotifier )
2830 		_pFileNotifier->notify( DIALOG_SIZE_CHANGED, 0 );
2831 }
2832 
2833 //*****************************************************************************
2834 
2835 //-----------------------------------------------------------------------------
2836 Control* SvtFileDialog::getControl( sal_Int16 _nControlId, sal_Bool _bLabelControl ) const
2837 {
2838 	Control* pReturn = NULL;
2839 
2840 	switch ( _nControlId )
2841 	{
2842 		case CONTROL_FILEVIEW:
2843 			pReturn = _bLabelControl ? NULL : static_cast< Control* >( _pFileView );
2844 			break;
2845 
2846 		case EDIT_FILEURL:
2847 			pReturn =	_bLabelControl
2848 					?	static_cast< Control* >( _pImp->_pFtFileName )
2849 					:	static_cast< Control* >( _pImp->_pEdFileName );
2850 			break;
2851 
2852 		case EDIT_FILEURL_LABEL:
2853 			pReturn = static_cast< Control* >( _pImp->_pFtFileName );
2854 			break;
2855 
2856 		case CHECKBOX_AUTOEXTENSION:
2857 			pReturn = _pImp->_pCbAutoExtension;
2858 			break;
2859 
2860 		case CHECKBOX_PASSWORD:
2861 			pReturn = _pImp->_pCbPassword;
2862 			break;
2863 
2864 		case CHECKBOX_FILTEROPTIONS:
2865 			pReturn = _pImp->_pCbOptions;
2866 			break;
2867 
2868 		case CHECKBOX_READONLY:
2869 			pReturn = _pCbReadOnly;
2870 			break;
2871 
2872 		case CHECKBOX_LINK:
2873 			pReturn = _pCbLinkBox;
2874 			break;
2875 
2876 		case CHECKBOX_PREVIEW:
2877 			pReturn = _pCbPreviewBox;
2878 			break;
2879 
2880 		case CHECKBOX_SELECTION:
2881 			pReturn = _pCbSelection;
2882 			break;
2883 
2884 		case LISTBOX_FILTER:
2885 			pReturn = _bLabelControl ? _pImp->_pFtFileType : _pImp->GetFilterListControl();
2886 			break;
2887 
2888 		case LISTBOX_FILTER_LABEL:
2889 			pReturn = _pImp->_pFtFileType;
2890 			break;
2891 
2892 		case FIXEDTEXT_CURRENTFOLDER:
2893 			pReturn = _pImp->_pFtCurrentPath;
2894 			break;
2895 
2896 		case LISTBOX_VERSION:
2897 			pReturn =	_bLabelControl
2898 					?	static_cast< Control* >( _pImp->_pFtFileVersion )
2899 					:	static_cast< Control* >( _pImp->_pLbFileVersion );
2900 			break;
2901 
2902 		case LISTBOX_TEMPLATE:
2903 			pReturn =	_bLabelControl
2904 					?	static_cast< Control* >( _pImp->_pFtTemplates )
2905 					:	static_cast< Control* >( _pImp->_pLbTemplates );
2906 			break;
2907 
2908 		case LISTBOX_IMAGE_TEMPLATE:
2909 			pReturn =	_bLabelControl
2910 					?	static_cast< Control* >( _pImp->_pFtImageTemplates )
2911 					:	static_cast< Control* >( _pImp->_pLbImageTemplates );
2912 			break;
2913 
2914 		case LISTBOX_VERSION_LABEL:
2915 			pReturn = _pImp->_pFtFileVersion;
2916 			break;
2917 
2918 		case LISTBOX_TEMPLATE_LABEL:
2919 			pReturn = _pImp->_pFtTemplates;
2920 			break;
2921 
2922 		case LISTBOX_IMAGE_TEMPLATE_LABEL:
2923 			pReturn = _pImp->_pFtImageTemplates;
2924 			break;
2925 
2926 		case PUSHBUTTON_OK:
2927 			pReturn = _pImp->_pBtnFileOpen;
2928 			break;
2929 
2930 		case PUSHBUTTON_CANCEL:
2931 			pReturn = _pImp->_pBtnCancel;
2932 			break;
2933 
2934 		case PUSHBUTTON_PLAY:
2935 			pReturn = _pPbPlay;
2936 			break;
2937 
2938 		case PUSHBUTTON_HELP:
2939 			pReturn = _pImp->_pBtnHelp;
2940 			break;
2941 
2942 		case TOOLBOXBUTOON_DEFAULT_LOCATION:
2943 			pReturn = _pImp->_pBtnStandard;
2944 			break;
2945 
2946 		case TOOLBOXBUTOON_LEVEL_UP:
2947 			pReturn = _pImp->_pBtnUp;
2948 			break;
2949 
2950 		case TOOLBOXBUTOON_NEW_FOLDER:
2951 			pReturn = _pImp->_pBtnNewFolder;
2952 			break;
2953 
2954         case LISTBOX_FILTER_SELECTOR:
2955             // only exists on SalGtkFilePicker
2956             break;
2957 
2958 		default:
2959 			DBG_ERRORFILE( "SvtFileDialog::getControl: invalid id!" );
2960 	}
2961 	return pReturn;
2962 }
2963 
2964 // -----------------------------------------------------------------------
2965 void SvtFileDialog::enableControl( sal_Int16 _nControlId, sal_Bool _bEnable )
2966 {
2967     Control* pControl = getControl( _nControlId, sal_False );
2968     if ( pControl )
2969         EnableControl( pControl, _bEnable );
2970     Control* pLabel = getControl( _nControlId, sal_True );
2971     if ( pLabel )
2972         EnableControl( pLabel, _bEnable );
2973 }
2974 
2975 // -----------------------------------------------------------------------
2976 void SvtFileDialog::AddControls_Impl( )
2977 {
2978 	// create the "insert as link" checkbox, if needed
2979     if ( _nExtraBits & SFX_EXTRA_INSERTASLINK )
2980 	{
2981 		_pCbLinkBox = new CheckBox( this );
2982         _pCbLinkBox ->SetText( SvtResId( STR_SVT_FILEPICKER_INSERT_AS_LINK ) );
2983 		_pCbLinkBox ->SetHelpId( HID_FILEDLG_LINK_CB );
2984 		AddControl( _pCbLinkBox  );
2985 		ReleaseOwnerShip( _pCbLinkBox );
2986 		_pCbLinkBox->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
2987 	}
2988 
2989 	// create the "show preview" checkbox ( and the preview window, too ), if needed
2990 	if ( _nExtraBits & SFX_EXTRA_SHOWPREVIEW  )
2991     {
2992     	_pImp->_aIniKey = IMPGRF_CONFIGNAME;
2993 		// because the "<All Formats> (*.bmp,*...)" entry is to wide,
2994 		// we need to disable the auto width feature of the filter box
2995 		_pImp->DisableFilterBoxAutoWidth();
2996 
2997         // "Vorschau"
2998 	    _pCbPreviewBox = new CheckBox( this );
2999 	    _pCbPreviewBox->SetText( SvtResId( STR_SVT_FILEPICKER_SHOW_PREVIEW ) );
3000 	    _pCbPreviewBox->SetHelpId( HID_FILEDLG_PREVIEW_CB );
3001 	    AddControl( _pCbPreviewBox );
3002 		ReleaseOwnerShip( _pCbPreviewBox );
3003 		_pCbPreviewBox->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
3004 
3005 	    // Preview-Fenster erst hier erzeugen
3006 	    _pPrevWin = new Window( this, WinBits( WB_BORDER ) );
3007 	    AddControl( _pPrevWin );
3008 		ReleaseOwnerShip( _pPrevWin );
3009         _pPrevWin->Hide();
3010 
3011         _pPrevBmp = new FixedBitmap( this, WinBits( WB_BORDER ) );
3012 	    _pPrevBmp->SetBackground( Wallpaper( Color( COL_WHITE ) ) );
3013         _pPrevBmp->Show();
3014 		_pPrevBmp->SetAccessibleName(SvtResId(STR_PREVIEW));
3015     }
3016 
3017     if ( _nExtraBits & SFX_EXTRA_AUTOEXTENSION )
3018     {
3019 		_pImp->_pCbAutoExtension = new CheckBox( this, SvtResId( CB_AUTO_EXTENSION ) );
3020 	    _pImp->_pCbAutoExtension->SetText( SvtResId( STR_SVT_FILEPICKER_AUTO_EXTENSION ) );
3021 		_pImp->_pCbAutoExtension->Check( sal_True );
3022 		AddControl( _pImp->_pCbAutoExtension );
3023 		ReleaseOwnerShip( _pImp->_pCbAutoExtension );
3024 		_pImp->_pCbAutoExtension->SetClickHdl( LINK( this, SvtFileDialog, AutoExtensionHdl_Impl ) );
3025     }
3026 
3027     if ( _nExtraBits & SFX_EXTRA_FILTEROPTIONS )
3028 	{
3029 		_pImp->_pCbOptions = new CheckBox( this, SvtResId( CB_OPTIONS ) );
3030 	    _pImp->_pCbOptions->SetText( SvtResId( STR_SVT_FILEPICKER_FILTER_OPTIONS ) );
3031 		AddControl( _pImp->_pCbOptions );
3032 		ReleaseOwnerShip( _pImp->_pCbOptions );
3033 		_pImp->_pCbOptions->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
3034 	}
3035 
3036     if ( _nExtraBits & SFX_EXTRA_SELECTION )
3037 	{
3038         _pCbSelection = new CheckBox( this, SvtResId( CB_OPTIONS ) );
3039 	    _pCbSelection->SetText( SvtResId( STR_SVT_FILEPICKER_SELECTION ) );
3040 		AddControl( _pCbSelection );
3041 		ReleaseOwnerShip( _pCbSelection );
3042 		_pCbSelection->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
3043 	}
3044 
3045     if ( _nExtraBits & SFX_EXTRA_PLAYBUTTON )
3046 	{
3047 		_pPbPlay = new PushButton( this );
3048 	    _pPbPlay->SetText( SvtResId( STR_SVT_FILEPICKER_PLAY ) );
3049 		_pPbPlay->SetHelpId( HID_FILESAVE_DOPLAY );
3050 		AddControl( _pPbPlay );
3051 		ReleaseOwnerShip( _pPbPlay );
3052 		_pPbPlay->SetClickHdl( LINK( this, SvtFileDialog, PlayButtonHdl_Impl ) );
3053 	}
3054 
3055 	if ( _nExtraBits & SFX_EXTRA_SHOWVERSIONS )
3056 	{
3057 		_pImp->_pFtFileVersion = new FixedText(	this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
3058 		_pImp->_pFtFileVersion->SetText( SvtResId( STR_SVT_FILEPICKER_VERSION ) );
3059 
3060 		_pImp->_pLbFileVersion = new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
3061 		_pImp->_pLbFileVersion->SetHelpId( HID_FILEOPEN_VERSION );
3062 	}
3063     else if ( _nExtraBits & SFX_EXTRA_TEMPLATES )
3064 	{
3065 		_pImp->_pFtTemplates = new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
3066 		_pImp->_pFtTemplates->SetText( SvtResId( STR_SVT_FILEPICKER_TEMPLATES ) );
3067 
3068 		_pImp->_pLbTemplates = new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
3069 		_pImp->_pLbTemplates->SetHelpId( HID_FILEOPEN_VERSION );
3070 			// This is strange. During the re-factoring during 96930, I discovered that this help id
3071 			// is set in the "Templates mode". This was hidden in the previous implementation.
3072 			// Shouldn't this be a more meaningfull help id.
3073 			// 96930 - 15.08.2002 - fs@openoffice.org
3074 	}
3075     else if ( _nExtraBits & SFX_EXTRA_IMAGE_TEMPLATE )
3076 	{
3077 		_pImp->_pFtImageTemplates = new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX ) );
3078 		_pImp->_pFtImageTemplates->SetText( SvtResId( STR_SVT_FILEPICKER_IMAGE_TEMPLATE ) );
3079 
3080 		_pImp->_pLbImageTemplates = new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX ) );
3081 		_pImp->_pLbImageTemplates->SetHelpId( HID_FILEOPEN_IMAGE_TEMPLATE );
3082 	}
3083 }
3084 
3085 // -----------------------------------------------------------------------
3086 sal_Int32 SvtFileDialog::getTargetColorDepth()
3087 {
3088     if ( _pPrevBmp )
3089         return _pPrevBmp->GetBitCount();
3090     else
3091         return 0;
3092 }
3093 
3094 // -----------------------------------------------------------------------
3095 sal_Int32 SvtFileDialog::getAvailableWidth()
3096 {
3097     if ( _pPrevBmp )
3098         return _pPrevBmp->GetOutputSizePixel().Width();
3099     else
3100         return 0;
3101 }
3102 
3103 // -----------------------------------------------------------------------
3104 sal_Int32 SvtFileDialog::getAvailableHeight()
3105 {
3106     if ( _pPrevBmp )
3107         return _pPrevBmp->GetOutputSizePixel().Height();
3108     else
3109         return 0;
3110 }
3111 
3112 // -----------------------------------------------------------------------
3113 void SvtFileDialog::setImage( sal_Int16 /*aImageFormat*/, const Any& rImage )
3114 {
3115     if ( ! _pPrevBmp || ! _pPrevBmp->IsVisible() )
3116         return;
3117 
3118     Sequence < sal_Int8 > aBmpSequence;
3119 
3120     if ( rImage >>= aBmpSequence )
3121     {
3122         Bitmap          aBmp;
3123         SvMemoryStream  aData( aBmpSequence.getArray(),
3124                                aBmpSequence.getLength(),
3125                                STREAM_READ );
3126         aData >> aBmp;
3127 
3128         _pPrevBmp->SetBitmap( aBmp );
3129     }
3130     else
3131     {
3132         Bitmap aEmpty;
3133         _pPrevBmp->SetBitmap( aEmpty );
3134     }
3135 }
3136 
3137 // -----------------------------------------------------------------------
3138 sal_Bool SvtFileDialog::setShowState( sal_Bool /*bShowState*/ )
3139 {
3140 	// #97633 for the system filedialog it's
3141 	// usefull to make the preview switchable
3142 	// because the preview occupies
3143 	// half of the size of the file listbox
3144 	// which is not the case here,
3145 	// so we (TRA/FS) decided not to make
3146 	// the preview window switchable because
3147 	// else we would have to change the layout
3148 	// of the file dialog dynamically
3149 	// support for set/getShowState is opionally
3150 	// see com::sun::star::ui::dialogs::XFilePreview
3151 	/*
3152     if ( _pPrevBmp )
3153     {
3154         _pPrevBmp->Show( bShowState );
3155         return sal_True;
3156     }
3157     else
3158         return sal_False;
3159 	*/
3160 
3161 	return sal_False;
3162 }
3163 
3164 // -----------------------------------------------------------------------
3165 String SvtFileDialog::getCurrentFileText( ) const
3166 {
3167 	String sReturn;
3168 	if ( _pImp && _pImp->_pEdFileName )
3169 		sReturn = _pImp->_pEdFileName->GetText();
3170 	return sReturn;
3171 }
3172 
3173 // -----------------------------------------------------------------------
3174 void SvtFileDialog::setCurrentFileText( const String& _rText, bool _bSelectAll )
3175 {
3176 	if ( _pImp && _pImp->_pEdFileName )
3177     {
3178 	    _pImp->_pEdFileName->SetText( _rText );
3179         if ( _bSelectAll )
3180             _pImp->_pEdFileName->SetSelection( Selection( 0, _rText.Len() ) );
3181     }
3182 }
3183 
3184 // -----------------------------------------------------------------------
3185 sal_Bool SvtFileDialog::isAutoExtensionEnabled()
3186 {
3187 	return _pImp->_pCbAutoExtension && _pImp->_pCbAutoExtension->IsChecked();
3188 }
3189 
3190 // -----------------------------------------------------------------------
3191 sal_Bool SvtFileDialog::getShowState()
3192 {
3193     if ( _pPrevBmp )
3194         return _pPrevBmp->IsVisible();
3195     else
3196         return sal_False;
3197 }
3198 
3199 // -----------------------------------------------------------------------
3200 void SvtFileDialog::ReleaseOwnerShip( Window* pUserControl )
3201 
3202 /*
3203   [Beschreibung]
3204   Die Methode sorgt dafuer das das spezifizierte Element nicht mehr im Besitz
3205   der Instanz ist.
3206 */
3207 
3208 {
3209 	ControlChain_Impl* pElement = _pUserControls;
3210 	while ( pElement )
3211 	{
3212 		if ( pElement->_pControl == pUserControl )
3213 		{
3214 			pElement->_bHasOwnerShip = sal_False;
3215 			break;
3216 		}
3217 		pElement = pElement->_pNext;
3218 	}
3219 }
3220 
3221 //***************************************************************************
3222 
3223 sal_Bool SvtFileDialog::AddControl( Window* pControl, sal_Bool bNewLine )
3224 {
3225 	// control already exists
3226 	ControlChain_Impl* pElement = _pUserControls;
3227 	while ( pElement )
3228 	{
3229 		if ( pElement->_pControl == pControl )
3230 			return sal_False;
3231 		pElement = pElement->_pNext;
3232 	}
3233 
3234 	// Check if controls have already been added.
3235 	Size aNewControlSize( pControl->GetOutputSizePixel() );
3236 	Size aDlgSize( GetOutputSizePixel() );
3237 	WindowType nType = pControl->GetType();
3238 	if ( !aNewControlSize.Height() )
3239 	{
3240 		// Detect a size.
3241 		Size aSize( 0, 10 );
3242 		if ( nType == WINDOW_PUSHBUTTON )
3243 		{
3244 			Size aDefSiz = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
3245 			long nTextWidth = pControl->GetTextWidth( pControl->GetText() );
3246 			aSize.Width() = nTextWidth + WIDTH_ADDITION;
3247 
3248 			// PushButton:	Mindestbreite 50 logische Einheiten,
3249 			//				H"ohe immer 14 logische Einheiten
3250 			if ( aDefSiz.Width() > aSize.Width() )
3251 				aSize.Width() = aDefSiz.Width();
3252 			aSize.Height() = aDefSiz.Height();
3253 			aNewControlSize = aSize;
3254 		}
3255 		else
3256 			aNewControlSize = LogicToPixel( aSize, MAP_APPFONT );
3257 		if ( nType != WINDOW_PUSHBUTTON )
3258 			aNewControlSize.Width() = pControl->GetTextWidth( pControl->GetText() ) + WIDTH_ADDITION;
3259 		if ( nType == WINDOW_CHECKBOX )
3260 			aNewControlSize.Width() += WIDTH_ADDITION;
3261 		if ( nType == WINDOW_WINDOW )
3262 		{
3263 			aNewControlSize.Height() = GetOutputSizePixel().Height() - 18;
3264 			aNewControlSize.Width() = 200;
3265 			aDlgSize.Width() += 210;
3266 			SetOutputSizePixel( aDlgSize );
3267 		}
3268 		pControl->SetOutputSizePixel( aNewControlSize );
3269 	}
3270 	Point aNewControlPos;
3271 	Size* pNewDlgSize = NULL;
3272 	sal_Bool bNewRow = bNewLine;
3273 	sal_Bool bFirstNewRow = sal_False;
3274 
3275 	if ( nType == WINDOW_WINDOW )
3276 	{
3277 		aNewControlPos.X() = aDlgSize.Width() - 210;
3278 		aNewControlPos.Y() = 8;
3279 	}
3280 	else if ( _pUserControls )
3281 	{
3282 		Point aNewControlRange( _pUserControls->_pControl->GetPosPixel() );
3283 		long nPrevControlHeight = _pUserControls->_pControl->GetSizePixel().Height();
3284 		aNewControlRange +=
3285 			Point( _pUserControls->_pControl->GetOutputSizePixel().Width(), 0 );
3286 		aNewControlPos = aNewControlRange;
3287 		if ( nPrevControlHeight > aNewControlSize.Height() )
3288 		{
3289 			long nY = nPrevControlHeight;
3290 			nY -= aNewControlSize.Height();
3291 			nY /= 2;
3292 			aNewControlPos.Y() += nY;
3293 		}
3294 		aNewControlPos += LogicToPixel( Point( 3, 0 ), MAP_APPFONT );
3295 		aNewControlRange += LogicToPixel( Point( 9, 0 ), MAP_APPFONT );
3296 		aNewControlRange += Point( aNewControlSize.Width(), 0 );
3297 
3298 		// Check if a new row has to be created.
3299 		if ( aNewControlRange.X() > aDlgSize.Width() )
3300 			bNewRow = sal_True;
3301 	}
3302 	else
3303 	{
3304 		// Create a new row if there was no usercontrol before.
3305 		bNewRow = sal_True;
3306 		bFirstNewRow = sal_True;
3307 	}
3308 
3309 	// Check if a new row has to be created.
3310 	Size aBorderSize = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
3311 	long nLeftBorder = aBorderSize.Width();
3312 	long nLowerBorder = aBorderSize.Height();
3313 	if ( bNewRow )
3314 	{
3315 		// Set control at the beginning of a new line.
3316 		long nSmallBorderHeight = nLowerBorder / 2;
3317 		aNewControlPos = Point( nLeftBorder, 0 );
3318 		aNewControlPos += Point( 0, aDlgSize.Height() );
3319 		aNewControlPos.Y() -= nSmallBorderHeight;
3320 		// Set new size.
3321 		pNewDlgSize = new Size( aDlgSize );
3322 		pNewDlgSize->Height() -= nSmallBorderHeight;
3323 		pNewDlgSize->Height() += aNewControlSize.Height();
3324 		pNewDlgSize->Height() += nLowerBorder;
3325 	}
3326 	else
3327 	{
3328 		// Check if the window has to be resized.
3329 		Size aNewControlRange( 0, aNewControlPos.Y() );
3330 		aNewControlRange.Height() += aNewControlSize.Height();
3331 		aNewControlRange.Height() += nLowerBorder;
3332 		if ( aNewControlRange.Height() > aDlgSize.Height() )
3333 			pNewDlgSize = new Size( aDlgSize.Width(), aNewControlRange.Height() );
3334 	}
3335 
3336 	// Update view.
3337 	if ( pNewDlgSize )
3338 	{
3339 		SetOutputSizePixel( *pNewDlgSize );
3340 		delete pNewDlgSize;
3341 	}
3342 	pControl->SetPosPixel( aNewControlPos );
3343 	pControl->Show();
3344 	_pUserControls = new ControlChain_Impl( pControl, _pUserControls );
3345 
3346 	return sal_True;
3347 }
3348 
3349 sal_Bool SvtFileDialog::ContentHasParentFolder( const rtl::OUString& rURL )
3350 {
3351 	m_aContent.bindTo( rURL );
3352 
3353 	if ( m_aContent.isInvalid() )
3354 		return sal_False;
3355 
3356 	return m_aContent.hasParentFolder( ) && m_aContent.isValid();
3357 }
3358 
3359 sal_Bool SvtFileDialog::ContentCanMakeFolder( const rtl::OUString& rURL )
3360 {
3361 	m_aContent.bindTo( rURL );
3362 
3363 	if ( m_aContent.isInvalid() )
3364 		return sal_False;
3365 
3366 	return m_aContent.canCreateFolder( ) && m_aContent.isValid();
3367 }
3368 
3369 sal_Bool SvtFileDialog::ContentGetTitle( const rtl::OUString& rURL, String& rTitle )
3370 {
3371 	m_aContent.bindTo( rURL );
3372 
3373 	if ( m_aContent.isInvalid() )
3374 		return sal_False;
3375 
3376 	::rtl::OUString sTitle;
3377 	m_aContent.getTitle( sTitle );
3378 	rTitle = sTitle;
3379 
3380 	return m_aContent.isValid();
3381 }
3382 
3383 void SvtFileDialog::appendDefaultExtension(String& _rFileName,
3384                                            const String& _rFilterDefaultExtension,
3385                                            const String& _rFilterExtensions)
3386 {
3387     String aTemp(_rFileName);
3388     aTemp.ToLowerAscii();
3389     String aType(_rFilterExtensions);
3390     aType.ToLowerAscii();
3391 
3392     if ( ! aType.EqualsAscii(FILEDIALOG_FILTER_ALL) )
3393     {
3394         sal_uInt16 nWildCard = aType.GetTokenCount( FILEDIALOG_DEF_EXTSEP );
3395         sal_uInt16 nIndex, nPos = 0;
3396 
3397         for ( nIndex = 0; nIndex < nWildCard; nIndex++ )
3398         {
3399             String aExt(aType.GetToken( 0, FILEDIALOG_DEF_EXTSEP, nPos ));
3400             // take care of a leading *
3401             sal_uInt16 nExtOffset = (aExt.GetBuffer()[0] == '*' ? 1 : 0);
3402             sal_Unicode* pExt = aExt.GetBufferAccess() + nExtOffset;
3403             xub_StrLen nExtLen = aExt.Len() - nExtOffset;
3404             xub_StrLen nOffset = aTemp.Len() - nExtLen;
3405             // minimize search by starting at last possible index
3406             if ( aTemp.Search(pExt, nOffset) == nOffset )
3407                 break;
3408         }
3409 
3410         if ( nIndex >= nWildCard )
3411         {
3412             _rFileName += '.';
3413             _rFileName += _rFilterDefaultExtension;
3414         }
3415     }
3416 }
3417 
3418 // -----------------------------------------------------------------------
3419 
3420 // QueryFolderNameDialog -------------------------------------------------------
3421 
3422 namespace svtools {
3423 
3424 QueryFolderNameDialog::QueryFolderNameDialog
3425 (
3426 	Window* _pParent,
3427 	const String& rTitle,
3428 	const String& rDefaultText,
3429 	String* pGroupName
3430 ) :
3431 	ModalDialog( _pParent, SvtResId( DLG_SVT_QUERYFOLDERNAME ) ),
3432 
3433 	aNameText	( this, SvtResId( FT_SVT_QUERYFOLDERNAME_DLG_NAME ) ),
3434 	aNameEdit	( this, SvtResId( ED_SVT_QUERYFOLDERNAME_DLG_NAME ) ),
3435 	aNameLine	( this, SvtResId( FL_SVT_QUERYFOLDERNAME_DLG_NAME ) ),
3436 	aOKBtn		( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_OK ) ),
3437 	aCancelBtn	( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_CANCEL ) )
3438 {
3439 	FreeResource();
3440 	SetText( rTitle );
3441 	aNameEdit.SetText( rDefaultText );
3442 	aNameEdit.SetSelection( Selection( 0, rDefaultText.Len() ) );
3443 	aOKBtn.SetClickHdl( LINK( this, QueryFolderNameDialog, OKHdl ) );
3444 	aNameEdit.SetModifyHdl( LINK( this, QueryFolderNameDialog, NameHdl ) );
3445 
3446 	if ( pGroupName )
3447 		aNameLine.SetText( *pGroupName );
3448 };
3449 
3450 // -----------------------------------------------------------------------
3451 IMPL_LINK( QueryFolderNameDialog, OKHdl, Button *, EMPTYARG )
3452 {
3453 	// trim the strings
3454 	aNameEdit.SetText( aNameEdit.GetText().EraseLeadingChars().EraseTrailingChars() );
3455 	EndDialog( RET_OK );
3456 	return 1;
3457 }
3458 
3459 // -----------------------------------------------------------------------
3460 IMPL_LINK( QueryFolderNameDialog, NameHdl, Edit *, EMPTYARG )
3461 {
3462 	// trim the strings
3463 	String aName = aNameEdit.GetText();
3464 	aName.EraseLeadingChars().EraseTrailingChars();
3465 	if ( aName.Len() )
3466 	{
3467 		if ( !aOKBtn.IsEnabled() )
3468 			aOKBtn.Enable( sal_True );
3469 	}
3470 	else
3471 	{
3472 		if ( aOKBtn.IsEnabled() )
3473 			aOKBtn.Enable( sal_False );
3474 	}
3475 
3476 	return 0;
3477 }
3478 
3479 }
3480