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