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