LCOV - code coverage report
Current view: top level - fpicker/source/office - iodlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 1326 0.1 %
Date: 2015-06-13 12:38:46 Functions: 2 129 1.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/macros.h>
      21             : #include "iodlg.hxx"
      22             : #include <svtools/PlaceEditDialog.hxx>
      23             : #include "PlacesListBox.hxx"
      24             : #include "fpsofficeResMgr.hxx"
      25             : #include <tools/stream.hxx>
      26             : #include <tools/urlobj.hxx>
      27             : #include <vcl/fixed.hxx>
      28             : #include <vcl/layout.hxx>
      29             : #include <vcl/lstbox.hxx>
      30             : #include <vcl/svapp.hxx>
      31             : #include <vcl/timer.hxx>
      32             : #include <unotools/ucbhelper.hxx>
      33             : #include "svtools/ehdl.hxx"
      34             : #include "svl/urihelper.hxx"
      35             : #include "unotools/pathoptions.hxx"
      36             : #include "unotools/viewoptions.hxx"
      37             : #include "svtools/fileview.hxx"
      38             : #include "svtools/sfxecode.hxx"
      39             : #include "svtools/svtabbx.hxx"
      40             : #include "svtools/treelistentry.hxx"
      41             : #include <toolkit/helper/vclunohelper.hxx>
      42             : #include <unotools/localfilehelper.hxx>
      43             : 
      44             : #include "svtools/helpid.hrc"
      45             : #include <svtools/svtools.hrc>
      46             : #include "OfficeFilePicker.hrc"
      47             : #include "iodlg.hrc"
      48             : #include "asyncfilepicker.hxx"
      49             : #include "iodlgimp.hxx"
      50             : #include "svtools/inettbc.hxx"
      51             : #include "unotools/syslocale.hxx"
      52             : #include "QueryFolderName.hxx"
      53             : #include <rtl/ustring.hxx>
      54             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      55             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      56             : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
      57             : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      58             : #include <com/sun/star/ui/dialogs/ControlActions.hpp>
      59             : #include <com/sun/star/beans/PropertyValue.hpp>
      60             : #include <com/sun/star/sdbc/XResultSet.hpp>
      61             : #include <com/sun/star/sdbc/XRow.hpp>
      62             : #include <com/sun/star/util/URL.hpp>
      63             : #include <com/sun/star/uno/Exception.hpp>
      64             : #include <com/sun/star/uno/Reference.hxx>
      65             : #include <com/sun/star/util/XURLTransformer.hpp>
      66             : #include <com/sun/star/uno/RuntimeException.hpp>
      67             : #include <com/sun/star/beans/XPropertySet.hpp>
      68             : 
      69             : #include <comphelper/interaction.hxx>
      70             : #include <comphelper/processfactory.hxx>
      71             : #include <comphelper/string.hxx>
      72             : 
      73             : #include <osl/file.h>
      74             : #include <vcl/dibtools.hxx>
      75             : #include <vcl/waitobj.hxx>
      76             : #include <vcl/settings.hxx>
      77             : 
      78             : #include <com/sun/star/task/InteractionHandler.hpp>
      79             : #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
      80             : #include "fpinteraction.hxx"
      81             : #include <osl/process.h>
      82             : 
      83             : #include <officecfg/Office/Common.hxx>
      84             : 
      85             : #include <algorithm>
      86             : #include <functional>
      87             : #include <vector>
      88             : 
      89             : //#define AUTOSELECT_USERFILTER
      90             :     // define this for the experimental feature of user-filter auto selection
      91             :     // means if the user enters e.g. *.doc<enter>, and there is a filter which is responsible for *.doc files (only),
      92             :     // then this filter is selected automatically
      93             : 
      94             : using namespace ::com::sun::star::beans;
      95             : using namespace ::com::sun::star::frame;
      96             : using namespace ::com::sun::star::ui::dialogs;
      97             : using namespace ::com::sun::star::uno;
      98             : using namespace ::com::sun::star::lang;
      99             : using namespace ::com::sun::star::ucb;
     100             : using namespace ::com::sun::star::container;
     101             : using namespace ::com::sun::star::task;
     102             : using namespace ::com::sun::star::sdbc;
     103             : using namespace ::utl;
     104             : using namespace ::svt;
     105             : 
     106             : using namespace ExtendedFilePickerElementIds;
     107             : using namespace CommonFilePickerElementIds;
     108             : using namespace InternalFilePickerElementIds;
     109             : 
     110             : #define GET_DECODED_NAME(aObj) \
     111             :     aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET )
     112             : 
     113             : // Time to wait while traveling in the filterbox until
     114             : // the browsebox gets filtered ( in ms).
     115             : #define TRAVELFILTER_TIMEOUT    750
     116             : 
     117             : // functions -------------------------------------------------------------
     118             : 
     119             : namespace
     120             : {
     121             : 
     122             : 
     123           0 :     OUString getMostCurrentFilter( SvtExpFileDlg_Impl* pImpl )
     124             :     {
     125             :         DBG_ASSERT( pImpl, "invalid impl pointer" );
     126           0 :         const SvtFileDialogFilter_Impl* pFilter = pImpl->_pUserFilter;
     127             : 
     128           0 :         if ( !pFilter )
     129           0 :             pFilter = pImpl->GetCurFilter();
     130             : 
     131           0 :         if ( !pFilter )
     132           0 :             return OUString();
     133             : 
     134           0 :         return pFilter->GetType();
     135             :     }
     136             : 
     137             : 
     138           0 :     bool restoreCurrentFilter( SvtExpFileDlg_Impl* _pImpl )
     139             :     {
     140             :         DBG_ASSERT( _pImpl->GetCurFilter(), "restoreCurrentFilter: no current filter!" );
     141             :         DBG_ASSERT( !_pImpl->GetCurFilterDisplayName().isEmpty(), "restoreCurrentFilter: no current filter (no display name)!" );
     142             : 
     143           0 :         _pImpl->SelectFilterListEntry( _pImpl->GetCurFilterDisplayName() );
     144             : 
     145             : #ifdef DBG_UTIL
     146             :         OUString sSelectedDisplayName;
     147             :         DBG_ASSERT( ( _pImpl->GetSelectedFilterEntry( sSelectedDisplayName ) == _pImpl->GetCurFilter() )
     148             :                 &&  ( sSelectedDisplayName == _pImpl->GetCurFilterDisplayName() ),
     149             :             "restoreCurrentFilter: inconsistence!" );
     150             : #endif
     151           0 :         return _pImpl->m_bNeedDelayedFilterExecute;
     152             :     }
     153             : 
     154             : 
     155           0 :     OUString GetFsysExtension_Impl( const OUString& rFile, const OUString& rLastFilterExt )
     156             :     {
     157           0 :         sal_Int32 nDotPos = rFile.lastIndexOf( '.' );
     158           0 :         if ( nDotPos != -1 )
     159             :         {
     160           0 :             if ( !rLastFilterExt.isEmpty() )
     161             :             {
     162           0 :                 if ( rFile.copy( nDotPos + 1 ).equalsIgnoreAsciiCase( rLastFilterExt ) )
     163           0 :                     return rLastFilterExt;
     164             :             }
     165             :             else
     166           0 :                 return rFile.copy( nDotPos );
     167             :         }
     168           0 :         return OUString();
     169             :     }
     170             : 
     171             : 
     172           0 :     void SetFsysExtension_Impl( OUString& rFile, const OUString& rExtension )
     173             :     {
     174           0 :         const sal_Unicode* p0 = rFile.getStr();
     175           0 :         const sal_Unicode* p1 = p0 + rFile.getLength() - 1;
     176           0 :         while ( p1 >= p0 && *p1 != '.' )
     177           0 :             p1--;
     178           0 :         if ( p1 >= p0 )
     179             :             // remove old extension
     180           0 :             rFile = rFile.copy( 0, p1 - p0 + 1 - ( rExtension.getLength() > 0 ? 0 : 1 ) );
     181           0 :         else if ( !rExtension.isEmpty() )
     182             :             // no old extension
     183           0 :             rFile += ".";
     184           0 :         rFile += rExtension;
     185           0 :     }
     186             : 
     187           0 :     void lcl_autoUpdateFileExtension( SvtFileDialog* _pDialog, const OUString& _rLastFilterExt )
     188             :     {
     189             :         // if auto extension is enabled ....
     190           0 :         if ( _pDialog->isAutoExtensionEnabled() )
     191             :         {
     192             :             // automatically switch to the extension of the (maybe just newly selected) extension
     193           0 :             OUString aNewFile = _pDialog->getCurrentFileText( );
     194           0 :             OUString aExt = GetFsysExtension_Impl( aNewFile, _rLastFilterExt );
     195             : 
     196             :             // but only if there already is an extension
     197           0 :             if ( !aExt.isEmpty() )
     198             :             {
     199             :                 // check if it is a real file extension, and not only the "post-dot" part in
     200             :                 // a directory name
     201           0 :                 bool bRealExtensions = true;
     202           0 :                 if ( -1 != aExt.indexOf( '/' ) )
     203           0 :                     bRealExtensions = false;
     204           0 :                 else if ( -1 != aExt.indexOf( '\\' ) )
     205           0 :                     bRealExtensions = false;
     206             :                 else
     207             :                 {
     208             :                     // no easy way to tell, because the part containing the dot already is the last
     209             :                     // segment of the complete file name
     210             :                     // So we have to check if the file name denotes a folder or a file.
     211             :                     // For performance reasons, we do this for file urls only
     212           0 :                     INetURLObject aURL( aNewFile );
     213           0 :                     if ( INetProtocol::NotValid == aURL.GetProtocol() )
     214             :                     {
     215           0 :                         OUString sURL;
     216           0 :                         if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aNewFile, sURL ) )
     217           0 :                             aURL = INetURLObject( sURL );
     218             :                     }
     219           0 :                     if ( INetProtocol::File == aURL.GetProtocol() )
     220             :                     {
     221             :                         try
     222             :                         {
     223           0 :                             bRealExtensions = !_pDialog->ContentIsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     224             :                         }
     225           0 :                         catch( const ::com::sun::star::uno::Exception& )
     226             :                         {
     227             :                             DBG_WARNING( "Exception in lcl_autoUpdateFileExtension" );
     228             :                         }
     229           0 :                     }
     230             :                 }
     231             : 
     232           0 :                 if ( bRealExtensions )
     233             :                 {
     234           0 :                     SetFsysExtension_Impl( aNewFile, _pDialog->GetDefaultExt() );
     235           0 :                     _pDialog->setCurrentFileText( aNewFile );
     236             :                 }
     237           0 :             }
     238             :         }
     239           0 :     }
     240             : 
     241             : 
     242           0 :     bool lcl_getHomeDirectory( const OUString& _rForURL, OUString& /* [out] */ _rHomeDir )
     243             :     {
     244           0 :         _rHomeDir.clear();
     245             : 
     246             :         // now ask the content broker for a provider for this scheme
     247             : 
     248             :         try
     249             :         {
     250             :             // get the provider for the current scheme
     251             :             Reference< XContentProvider > xProvider(
     252             :                 UniversalContentBroker::create(
     253           0 :                     comphelper::getProcessComponentContext() )->
     254           0 :                 queryContentProvider( _rForURL ) );
     255             : 
     256             :             DBG_ASSERT( xProvider.is(), "lcl_getHomeDirectory: could not find a (valid) content provider for the current URL!" );
     257           0 :             Reference< XPropertySet > xProviderProps( xProvider, UNO_QUERY );
     258           0 :             if ( xProviderProps.is() )
     259             :             {
     260           0 :                 Reference< XPropertySetInfo > xPropInfo = xProviderProps->getPropertySetInfo();
     261           0 :                 const OUString sHomeDirPropertyName( "HomeDirectory" );
     262           0 :                 if ( !xPropInfo.is() || xPropInfo->hasPropertyByName( sHomeDirPropertyName ) )
     263             :                 {
     264           0 :                     OUString sHomeDirectory;
     265           0 :                     xProviderProps->getPropertyValue( sHomeDirPropertyName ) >>= sHomeDirectory;
     266           0 :                     _rHomeDir = sHomeDirectory;
     267           0 :                 }
     268           0 :             }
     269             :         }
     270           0 :         catch( const Exception& )
     271             :         {
     272             :             OSL_FAIL( "lcl_getHomeDirectory: caught an exception!" );
     273             :         }
     274           0 :         return !_rHomeDir.isEmpty();
     275             :     }
     276             : 
     277             : 
     278           0 :     static OUString lcl_ensureFinalSlash( const OUString& _rDir )
     279             :     {
     280           0 :         INetURLObject aWorkPathObj( _rDir, INetProtocol::File );
     281           0 :         aWorkPathObj.setFinalSlash();
     282           0 :         return  aWorkPathObj.GetMainURL( INetURLObject::NO_DECODE );
     283             :     }
     284             : 
     285             : 
     286             :     /** retrieves the value of an environment variable
     287             :         @return <TRUE/> if and only if the retrieved string value is not empty
     288             :     */
     289           0 :     bool getEnvironmentValue( const sal_Char* _pAsciiEnvName, OUString& _rValue )
     290             :     {
     291           0 :         _rValue.clear();
     292           0 :         OUString sEnvName = OUString::createFromAscii( _pAsciiEnvName );
     293           0 :         osl_getEnvironment( sEnvName.pData, &_rValue.pData );
     294           0 :         return !_rValue.isEmpty();
     295             :     }
     296             : }
     297             : 
     298             : // SvtFileDialog
     299             : 
     300           0 : SvtFileDialog::SvtFileDialog
     301             : (
     302             :     vcl::Window* _pParent,
     303             :     WinBits nBits,
     304             :     WinBits nExtraBits
     305             : ) :
     306             :     ModalDialog( _pParent, "ExplorerFileDialog", "fps/ui/explorerfiledialog.ui" )
     307             : 
     308             :     ,_pCbReadOnly( NULL )
     309             :     ,_pCbLinkBox( NULL)
     310             :     ,_pCbPreviewBox( NULL )
     311             :     ,_pCbSelection( NULL )
     312             :     ,_pPbPlay( NULL )
     313             :     ,_pPrevWin( NULL )
     314             :     ,_pPrevBmp( NULL )
     315             :     ,_pFileView( NULL )
     316             :     ,_pFileNotifier( NULL )
     317           0 :     ,_pImp( new SvtExpFileDlg_Impl( nBits ) )
     318             :     ,_nExtraBits( nExtraBits )
     319             :     ,_bIsInExecute( false )
     320             :     ,m_bInExecuteAsync( false )
     321             :     ,m_bHasFilename( false )
     322           0 :     ,m_context(comphelper::getProcessComponentContext())
     323             : {
     324           0 :     Init_Impl( nBits );
     325           0 : }
     326             : 
     327             : 
     328             : 
     329           0 : SvtFileDialog::SvtFileDialog ( vcl::Window* _pParent, WinBits nBits )
     330             :     :ModalDialog( _pParent, "ExplorerFileDialog", "fps/ui/explorerfiledialog.ui" )
     331             :     ,_pCbReadOnly( NULL )
     332             :     ,_pCbLinkBox( NULL)
     333             :     ,_pCbPreviewBox( NULL )
     334             :     ,_pCbSelection( NULL )
     335             :     ,_pPbPlay( NULL )
     336             :     ,_pPrevWin( NULL )
     337             :     ,_pPrevBmp( NULL )
     338             :     ,_pFileView( NULL )
     339             :     ,_pFileNotifier( NULL )
     340           0 :     ,_pImp( new SvtExpFileDlg_Impl( nBits ) )
     341             :     ,_nExtraBits( 0L )
     342             :     ,_bIsInExecute( false )
     343           0 :     ,m_bHasFilename( false )
     344             : {
     345           0 :     Init_Impl( nBits );
     346           0 : }
     347             : 
     348             : class CustomContainer : public vcl::Window
     349             : {
     350             :     SvtExpFileDlg_Impl* _pImp;
     351             :     VclPtr<SvtFileView> _pFileView;
     352             :     VclPtr<Splitter>    _pSplitter;
     353             : 
     354             : public:
     355           0 :     CustomContainer(vcl::Window *pParent)
     356             :         : Window(pParent)
     357             :         , _pImp(NULL)
     358             :         , _pFileView(NULL)
     359           0 :         , _pSplitter(NULL)
     360             :     {
     361           0 :     }
     362           0 :     virtual ~CustomContainer() { disposeOnce(); }
     363           0 :     virtual void dispose() SAL_OVERRIDE
     364             :     {
     365           0 :         _pFileView.clear();
     366           0 :         _pSplitter.clear();
     367           0 :         vcl::Window::dispose();
     368           0 :     }
     369             : 
     370           0 :     void init(SvtExpFileDlg_Impl* pImp,
     371             :               SvtFileView* pFileView,
     372             :               Splitter* pSplitter)
     373             :     {
     374           0 :         _pImp = pImp;
     375           0 :         _pFileView = pFileView;
     376           0 :         _pSplitter = pSplitter;
     377           0 :     }
     378             : 
     379           0 :     virtual void Resize() SAL_OVERRIDE
     380             :     {
     381           0 :         Window::Resize();
     382             : 
     383           0 :         if (!_pImp || !_pImp->_pPlaces)
     384           0 :             return;
     385             : 
     386           0 :         Size aSize = GetSizePixel();
     387             : 
     388           0 :         Point aBoxPos(_pFileView->GetPosPixel());
     389           0 :         Size aNewSize(aSize.Width() - aBoxPos.X(), aSize.Height());
     390           0 :         _pFileView->SetSizePixel( aNewSize );
     391             : 
     392             :         // Resize the Splitter to fit the height
     393           0 :         Size splitterNewSize = _pSplitter->GetSizePixel( );
     394           0 :         splitterNewSize.Height() = aSize.Height();
     395           0 :         _pSplitter->SetSizePixel( splitterNewSize );
     396           0 :         sal_Int32 nMinX = _pImp->_pPlaces->GetPosPixel( ).X( );
     397           0 :         sal_Int32 nMaxX = _pFileView->GetPosPixel( ).X( ) + _pFileView->GetSizePixel( ).Width() - nMinX;
     398           0 :         _pSplitter->SetDragRectPixel( Rectangle( Point( nMinX, 0 ), Size( nMaxX, aSize.Width() ) ) );
     399             : 
     400             :         // Resize the places list box to fit the height of the FileView
     401           0 :         Size placesNewSize(_pImp->_pPlaces->GetSizePixel());
     402           0 :         placesNewSize.Height() = aSize.Height();
     403           0 :         _pImp->_pPlaces->SetSizePixel( placesNewSize );
     404             :     }
     405             : 
     406           0 :     virtual void GetFocus() SAL_OVERRIDE
     407             :     {
     408           0 :         _pFileView->GrabFocus();
     409           0 :     }
     410             : };
     411             : 
     412           0 : SvtFileDialog::~SvtFileDialog()
     413             : {
     414           0 :     disposeOnce();
     415           0 : }
     416             : 
     417           0 : void SvtFileDialog::dispose()
     418             : {
     419           0 :     if ( !_pImp->_aIniKey.isEmpty() )
     420             :     {
     421             :         // save window state
     422           0 :         SvtViewOptions aDlgOpt( E_DIALOG, _pImp->_aIniKey );
     423           0 :         aDlgOpt.SetWindowState(OStringToOUString(GetWindowState(), osl_getThreadTextEncoding()));
     424           0 :         OUString sUserData = _pFileView->GetConfigString();
     425             :         aDlgOpt.SetUserItem( OUString( "UserData" ),
     426           0 :                              makeAny( sUserData ) );
     427             :     }
     428             : 
     429           0 :     _pFileView->SetSelectHdl( Link<>() );
     430             : 
     431             :     // Save bookmarked places
     432           0 :     if(_pImp->_pPlaces->IsUpdated()) {
     433           0 :         const std::vector<PlacePtr> aPlaces = _pImp->_pPlaces->GetPlaces();
     434           0 :         Sequence< OUString > placesUrlsList(_pImp->_pPlaces->GetNbEditablePlaces());
     435           0 :         Sequence< OUString > placesNamesList(_pImp->_pPlaces->GetNbEditablePlaces());
     436           0 :         int i(0);
     437           0 :         for(std::vector<PlacePtr>::const_iterator it = aPlaces.begin(); it != aPlaces.end(); ++it) {
     438           0 :             if((*it)->IsEditable()) {
     439           0 :                 placesUrlsList[i] = (*it)->GetUrl();
     440           0 :                 placesNamesList[i] = (*it)->GetName();
     441           0 :                 ++i;
     442             :             }
     443             :         }
     444             : 
     445           0 :         std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_context));
     446           0 :         officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
     447           0 :         officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
     448           0 :         batch->commit();
     449             :     }
     450             : 
     451           0 :     delete _pImp;
     452           0 :     _pFileView.disposeAndClear();
     453           0 :     _pSplitter.disposeAndClear();
     454           0 :     _pContainer.disposeAndClear();
     455           0 :     _pPrevBmp.disposeAndClear();
     456           0 :     _pCbReadOnly.clear();
     457           0 :     _pCbLinkBox.clear();
     458           0 :     _pCbPreviewBox.clear();
     459           0 :     _pCbSelection.clear();
     460           0 :     _pPbPlay.clear();
     461           0 :     _pPrevWin.clear();
     462           0 :     ModalDialog::dispose();
     463           0 : }
     464             : 
     465           0 : void SvtFileDialog::Init_Impl
     466             : (
     467             :     WinBits nStyle
     468             : )
     469             : {
     470           0 :     get(_pCbReadOnly, "readonly");
     471           0 :     get(_pCbLinkBox, "link");
     472           0 :     get(_pCbPreviewBox, "cb_preview");
     473           0 :     get(_pCbSelection, "selection");
     474           0 :     get(_pPrevWin, "preview");
     475           0 :     get(_pPbPlay, "play");
     476           0 :     get(_pImp->_pCbOptions, "options");
     477           0 :     get(_pImp->_pFtFileName, "file_name_label");
     478           0 :     get(_pImp->_pEdFileName, "file_name");
     479           0 :     _pImp->_pEdFileName->GetFocus();
     480           0 :     get(_pImp->_pFtFileType, "file_type_label");
     481           0 :     get(_pImp->_pLbFilter, "file_type");
     482           0 :     get(_pImp->_pEdCurrentPath, "current_path");
     483           0 :     get(_pImp->_pBtnFileOpen, "open");
     484           0 :     get(_pImp->_pBtnCancel, "cancel");
     485           0 :     get(_pImp->_pBtnHelp, "help");
     486           0 :     get(_pImp->_pBtnConnectToServer, "connect_to_server");
     487           0 :     get(_pImp->_pBtnNewFolder, "new_folder");
     488           0 :     get(_pImp->_pCbPassword, "password");
     489           0 :     get(_pImp->_pCbAutoExtension, "extension");
     490           0 :     get(_pImp->_pFtFileVersion, "shared_label");
     491           0 :     get(_pImp->_pLbFileVersion, "shared");
     492           0 :     get(_pImp->_pFtTemplates, "shared_label");
     493           0 :     get(_pImp->_pLbTemplates, "shared");
     494           0 :     get(_pImp->_pFtImageTemplates, "shared_label");
     495           0 :     get(_pImp->_pLbImageTemplates, "shared");
     496             : 
     497           0 :     _pImp->_pLbImageTemplates->setMaxWidthChars(40);
     498           0 :     _pImp->_pLbFilter->setMaxWidthChars(40);
     499             : 
     500           0 :     m_aImages = ImageList( SvtResId( RID_FILEPICKER_IMAGES ) );
     501           0 :     vcl::Window *pUpContainer = get<vcl::Window>("up");
     502           0 :     _pImp->_pBtnUp = VclPtr<SvtUpButton_Impl>::Create(pUpContainer, this, 0);
     503           0 :     _pImp->_pBtnUp->SetHelpId( HID_FILEOPEN_LEVELUP );
     504           0 :     _pImp->_pBtnUp->set_vexpand(true);
     505           0 :     _pImp->_pBtnUp->Show();
     506             : 
     507           0 :     _pImp->_nStyle = nStyle;
     508           0 :     _pImp->_eMode = ( nStyle & WB_SAVEAS ) ? FILEDLG_MODE_SAVE : FILEDLG_MODE_OPEN;
     509           0 :     _pImp->_eDlgType = FILEDLG_TYPE_FILEDLG;
     510             : 
     511           0 :     if ( ( nStyle & SFXWB_PATHDIALOG ) == SFXWB_PATHDIALOG )
     512           0 :         _pImp->_eDlgType = FILEDLG_TYPE_PATHDLG;
     513             : 
     514             :     // Set the directory for the "back to the default dir" button
     515           0 :     INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
     516           0 :     SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
     517             : 
     518             :     // determine range
     519           0 :     if ( !( nStyle & SFXWB_NOREMOTE ) )
     520             :     {
     521           0 :         _pImp->_nState |= FILEDLG_STATE_REMOTE;
     522             :     }
     523             : 
     524             :     // Create control element, the order defines the tab control.
     525           0 :     _pImp->_pEdFileName->SetSelectHdl( LINK( this, SvtFileDialog, EntrySelectHdl_Impl ) );
     526           0 :     _pImp->_pEdFileName->SetOpenHdl( LINK( this, SvtFileDialog, OpenHdl_Impl ) );
     527             : 
     528             :     // in folder picker mode, only auto-complete directories (no files)
     529           0 :     bool bIsFolderPicker = ( _pImp->_eDlgType == FILEDLG_TYPE_PATHDLG );
     530           0 :     _pImp->_pEdFileName->SetOnlyDirectories( bIsFolderPicker );
     531             : 
     532             :     // in save mode, don't use the autocompletion as selection in the edit part
     533           0 :     bool bSaveMode = ( FILEDLG_MODE_SAVE == _pImp->_eMode );
     534           0 :     _pImp->_pEdFileName->SetNoURLSelection( bSaveMode );
     535             : 
     536           0 :     _pImp->_pBtnConnectToServer->SetAccessibleName( _pImp->_pBtnConnectToServer->GetQuickHelpText() );
     537           0 :     _pImp->_pBtnNewFolder->SetStyle( _pImp->_pBtnNewFolder->GetStyle() | WB_NOPOINTERFOCUS );
     538           0 :     _pImp->_pBtnUp->SetAccessibleName( _pImp->_pBtnUp->GetQuickHelpText() );
     539           0 :     _pImp->_pBtnNewFolder->SetAccessibleName( _pImp->_pBtnNewFolder->GetQuickHelpText() );
     540             : 
     541           0 :     if ( ( nStyle & SFXWB_MULTISELECTION ) == SFXWB_MULTISELECTION )
     542           0 :         _pImp->_bMultiSelection = true;
     543             : 
     544           0 :     _pContainer.reset(VclPtr<CustomContainer>::Create(get<vcl::Window>("container")));
     545           0 :     Size aSize(LogicToPixel(Size(270, 85), MAP_APPFONT));
     546           0 :     _pContainer->set_height_request(aSize.Height());
     547           0 :     _pContainer->set_width_request(aSize.Width());
     548           0 :     _pContainer->set_hexpand(true);
     549           0 :     _pContainer->set_vexpand(true);
     550           0 :     _pContainer->SetStyle( _pContainer->GetStyle() | WB_TABSTOP );
     551             : 
     552           0 :     _pFileView = VclPtr<SvtFileView>::Create( _pContainer, WB_BORDER,
     553           0 :                                        FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType,
     554           0 :                                        _pImp->_bMultiSelection );
     555           0 :     _pFileView->Show();
     556           0 :     _pFileView->EnableAutoResize();
     557           0 :     _pFileView->SetHelpId( HID_FILEDLG_STANDARD );
     558           0 :     _pFileView->SetStyle( _pFileView->GetStyle() | WB_TABSTOP );
     559             : 
     560           0 :     _pSplitter = VclPtr<Splitter>::Create( _pContainer, WB_HSCROLL );
     561           0 :     _pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
     562           0 :     _pSplitter->SetSplitHdl( LINK( this, SvtFileDialog, Split_Hdl ) );
     563             : 
     564           0 :     Image aNewFolderImg( GetButtonImage( IMG_FILEDLG_CREATEFOLDER ) );
     565           0 :     _pImp->_pBtnNewFolder->SetModeImage( aNewFolderImg );
     566             : 
     567           0 :     if ( nStyle & SFXWB_READONLY )
     568             :     {
     569           0 :         _pCbReadOnly->SetHelpId( HID_FILEOPEN_READONLY );
     570           0 :         _pCbReadOnly->SetText( SvtResId( STR_SVT_FILEPICKER_READONLY ) );
     571           0 :         _pCbReadOnly->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
     572           0 :         _pCbReadOnly->Show();
     573             :     }
     574             : 
     575           0 :     if ( nStyle & SFXWB_PASSWORD )
     576             :     {
     577           0 :         _pImp->_pCbPassword->SetText( SvtResId( STR_SVT_FILEPICKER_PASSWORD ) );
     578           0 :         _pImp->_pCbPassword->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
     579           0 :         _pImp->_pCbPassword->Show();
     580             :     }
     581             : 
     582             :     // set the ini file for extracting the size
     583           0 :     _pImp->_aIniKey = "FileDialog";
     584             : 
     585           0 :     AddControls_Impl( );
     586             : 
     587             :     // adjust the labels to the mode
     588           0 :     sal_uInt16 nResId = STR_EXPLORERFILE_OPEN;
     589           0 :     sal_uInt16 nButtonResId = 0;
     590             : 
     591           0 :     if ( nStyle & WB_SAVEAS )
     592             :     {
     593           0 :         nResId = STR_EXPLORERFILE_SAVE;
     594           0 :         nButtonResId = STR_EXPLORERFILE_BUTTONSAVE;
     595             :     }
     596             : 
     597           0 :     if ( ( nStyle & SFXWB_PATHDIALOG ) == SFXWB_PATHDIALOG )
     598             :     {
     599           0 :         _pImp->_pFtFileName->SetText( SvtResId( STR_PATHNAME ) );
     600           0 :         nResId = STR_PATHSELECT;
     601           0 :         nButtonResId = STR_BUTTONSELECT;
     602             :     }
     603             : 
     604           0 :     SetText( SvtResId( nResId ) );
     605             : 
     606           0 :     if ( nButtonResId )
     607           0 :         _pImp->_pBtnFileOpen->SetText( SvtResId( nButtonResId ) );
     608             : 
     609           0 :     if ( FILEDLG_TYPE_FILEDLG != _pImp->_eDlgType )
     610             :     {
     611           0 :         _pImp->_pFtFileType->Hide();
     612           0 :         _pImp->GetFilterListControl()->Hide();
     613             :     }
     614             : 
     615             :     // Setting preferences of the control elements.
     616           0 :     _pImp->_pBtnNewFolder->SetClickHdl( LINK( this, SvtFileDialog, NewFolderHdl_Impl ) );
     617           0 :     _pImp->_pBtnFileOpen->SetClickHdl( LINK( this, SvtFileDialog, OpenHdl_Impl ) );
     618           0 :     _pImp->_pBtnCancel->SetClickHdl( LINK( this, SvtFileDialog, CancelHdl_Impl ) );
     619           0 :     _pImp->SetFilterListSelectHdl( LINK( this, SvtFileDialog, FilterSelectHdl_Impl ) );
     620           0 :     _pImp->_pEdFileName->SetGetFocusHdl( LINK( this, SvtFileDialog, FileNameGetFocusHdl_Impl ) );
     621           0 :     _pImp->_pEdFileName->SetModifyHdl( LINK( this, SvtFileDialog, FileNameModifiedHdl_Impl ) );
     622           0 :     _pImp->_pEdCurrentPath->SetOpenHdl ( LINK( this, SvtFileDialog, URLBoxModifiedHdl_Impl ) );
     623           0 :     _pImp->_pBtnConnectToServer->SetClickHdl( LINK ( this, SvtFileDialog, ConnectToServerPressed_Hdl ) );
     624             : 
     625             : 
     626           0 :     _pFileView->SetSelectHdl( LINK( this, SvtFileDialog, SelectHdl_Impl ) );
     627           0 :     _pFileView->SetDoubleClickHdl( LINK( this, SvtFileDialog, DblClickHdl_Impl ) );
     628           0 :     _pFileView->SetOpenDoneHdl( LINK( this, SvtFileDialog, OpenDoneHdl_Impl ) );
     629             : 
     630             : 
     631             :     // set timer for the filterbox travel
     632           0 :     _pImp->_aFilterTimer.SetTimeout( TRAVELFILTER_TIMEOUT );
     633           0 :     _pImp->_aFilterTimer.SetTimeoutHdl( LINK( this, SvtFileDialog, FilterSelectTimerHdl_Impl ) );
     634             : 
     635           0 :     if ( WB_SAVEAS & nStyle )
     636             :     {
     637             :         // different help ids if in save-as mode
     638           0 :         SetHelpId( HID_FILESAVE_DIALOG );
     639             : 
     640           0 :         _pImp->_pEdFileName->SetHelpId( HID_FILESAVE_FILEURL );
     641           0 :         _pImp->_pBtnFileOpen->SetHelpId( HID_FILESAVE_DOSAVE );
     642           0 :         _pImp->_pBtnNewFolder->SetHelpId( HID_FILESAVE_CREATEDIRECTORY );
     643           0 :         _pImp->_pBtnUp->SetHelpId( HID_FILESAVE_LEVELUP );
     644           0 :         _pImp->GetFilterListControl()->SetHelpId( HID_FILESAVE_FILETYPE );
     645           0 :         _pFileView->SetHelpId( HID_FILESAVE_FILEVIEW );
     646             : 
     647             :         // formerly, there was only _pLbFileVersion, which was used for 3 different
     648             :         // use cases. For reasons of maintainability, I introduced extra members (_pLbTemplates, _pLbImageTemplates)
     649             :         // for the extra use cases, and separated _pLbFileVersion
     650             :         // I did not find out in which cases the help ID is really needed HID_FILESAVE_TEMPLATE - all
     651             :         // tests I made lead to a dialog where _no_ of the three list boxes was present.
     652           0 :         if ( _pImp->_pLbFileVersion )
     653           0 :             _pImp->_pLbFileVersion->SetHelpId( HID_FILESAVE_TEMPLATE );
     654           0 :         if ( _pImp->_pLbTemplates )
     655           0 :             _pImp->_pLbTemplates->SetHelpId( HID_FILESAVE_TEMPLATE );
     656           0 :         if ( _pImp->_pLbImageTemplates )
     657           0 :             _pImp->_pLbImageTemplates->SetHelpId( HID_FILESAVE_TEMPLATE );
     658             : 
     659           0 :         if ( _pImp->_pCbPassword ) _pImp->_pCbPassword->SetHelpId( HID_FILESAVE_SAVEWITHPASSWORD );
     660           0 :         if ( _pImp->_pCbAutoExtension ) _pImp->_pCbAutoExtension->SetHelpId( HID_FILESAVE_AUTOEXTENSION );
     661           0 :         if ( _pImp->_pCbOptions ) _pImp->_pCbOptions->SetHelpId( HID_FILESAVE_CUSTOMIZEFILTER );
     662           0 :         if ( _pCbSelection ) _pCbSelection->SetHelpId( HID_FILESAVE_SELECTION );
     663             :     }
     664             : 
     665             :     /// read our settings from the configuration
     666           0 :     m_aConfiguration = OConfigurationTreeRoot::createWithComponentContext(
     667             :         ::comphelper::getProcessComponentContext(),
     668             :         OUString( "/org.openoffice.Office.UI/FilePicker" )
     669           0 :     );
     670             : 
     671           0 :     _pContainer->init(_pImp, _pFileView, _pSplitter);
     672           0 :     _pContainer->Show();
     673             : 
     674           0 :     Resize();
     675           0 : }
     676             : 
     677           0 : IMPL_LINK( SvtFileDialog, NewFolderHdl_Impl, PushButton*, )
     678             : {
     679           0 :     _pFileView->EndInplaceEditing( false );
     680             : 
     681           0 :     SmartContent aContent( _pFileView->GetViewURL( ) );
     682           0 :     OUString aTitle;
     683           0 :     aContent.getTitle( aTitle );
     684           0 :     ScopedVclPtrInstance< QueryFolderNameDialog > aDlg(this, aTitle, SVT_RESSTR(STR_SVT_NEW_FOLDER));
     685           0 :     bool bHandled = false;
     686             : 
     687           0 :     while ( !bHandled )
     688             :     {
     689           0 :         if ( aDlg->Execute() == RET_OK )
     690             :         {
     691           0 :             OUString aUrl = aContent.createFolder( aDlg->GetName( ) );
     692           0 :             if ( !aUrl.isEmpty( ) )
     693             :             {
     694           0 :                 _pFileView->CreatedFolder( aUrl, aDlg->GetName() );
     695           0 :                 bHandled = true;
     696           0 :             }
     697             :         }
     698             :         else
     699           0 :             bHandled = true;
     700             :     }
     701             : 
     702           0 :     return 0;
     703             : }
     704             : 
     705           0 : bool SvtFileDialog::createNewUserFilter( const OUString& _rNewFilter, bool _bAllowUserDefExt )
     706             : {
     707             :     // delete the old user filter and create a new one
     708           0 :     DELETEZ( _pImp->_pUserFilter );
     709           0 :     _pImp->_pUserFilter = new SvtFileDialogFilter_Impl( _rNewFilter, _rNewFilter );
     710             : 
     711             :     // remember the extension
     712           0 :     bool bIsAllFiles = _rNewFilter == FILEDIALOG_FILTER_ALL;
     713           0 :     if ( bIsAllFiles )
     714           0 :         EraseDefaultExt();
     715             :     else
     716           0 :         SetDefaultExt( _rNewFilter.copy( 2 ) );
     717             :         // TODO: this is nonsense. In the whole file there are a lotta places where we assume that a user filter
     718             :         // is always "*.<something>". But changing this would take some more time than I have now ...
     719             : 
     720             :     // now, the default extension is set to the one of the user filter (or empty)
     721             :     // if the former is not allowed (_bAllowUserDefExt = <FALSE/>), we have to use the ext of the current filter
     722             :     // (if possible)
     723           0 :     bool bUseCurFilterExt = true;
     724           0 :     OUString sUserFilter = _pImp->_pUserFilter->GetType();
     725           0 :     sal_Int32 nSepPos = sUserFilter.lastIndexOf( '.' );
     726           0 :     if ( nSepPos != -1 )
     727             :     {
     728           0 :         OUString sUserExt = sUserFilter.copy( nSepPos + 1 );
     729           0 :         if  (   ( -1 == sUserExt.indexOf( '*' ) )
     730           0 :             &&  ( -1 == sUserExt.indexOf( '?' ) )
     731             :             )
     732           0 :             bUseCurFilterExt = false;
     733             :     }
     734             : 
     735           0 :     if ( !_bAllowUserDefExt || bUseCurFilterExt )
     736             :     {
     737           0 :         if ( _pImp->GetCurFilter( ) )
     738           0 :             SetDefaultExt( _pImp->GetCurFilter( )->GetExtension() );
     739             :         else
     740           0 :             EraseDefaultExt();
     741             :     }
     742             : 
     743             :     // outta here
     744           0 :     return bIsAllFiles;
     745             : }
     746             : 
     747             : 
     748             : #define FLT_NONEMPTY        0x0001
     749             : #define FLT_CHANGED         0x0002
     750             : #define FLT_USERFILTER      0x0004
     751             : #define FLT_ALLFILESFILTER  0x0008
     752             : 
     753             : 
     754           0 : sal_uInt16 SvtFileDialog::adjustFilter( const OUString& _rFilter )
     755             : {
     756           0 :     sal_uInt16 nReturn = 0;
     757             : 
     758           0 :     const bool bNonEmpty = !_rFilter.isEmpty();
     759           0 :     if ( bNonEmpty )
     760             :     {
     761           0 :         nReturn |= FLT_NONEMPTY;
     762             : 
     763           0 :         bool bFilterChanged = true;
     764             : 
     765             :         // search for a corresponding filter
     766           0 :         SvtFileDialogFilter_Impl* pFilter = FindFilter_Impl( _rFilter, false, bFilterChanged );
     767             : 
     768             : #ifdef AUTOSELECT_USERFILTER
     769             :         // if we found a filter which without allowing multi-extensions -> select it
     770             :         if ( pFilter )
     771             :         {
     772             :             _pImp->SelectFilterListEntry( pFilter->GetName() );
     773             :             _pImp->SetCurFilter( pFilter );
     774             :         }
     775             : #endif // AUTOSELECT_USERFILTER
     776             : 
     777             :         // look for multi-ext filters if necessary
     778           0 :         if ( !pFilter )
     779           0 :             pFilter = FindFilter_Impl( _rFilter, true, bFilterChanged );
     780             : 
     781           0 :         if ( bFilterChanged )
     782           0 :             nReturn |= FLT_CHANGED;
     783             : 
     784           0 :         if ( !pFilter )
     785             :         {
     786           0 :             nReturn |= FLT_USERFILTER;
     787             :             // no filter found : use it as user defined filter
     788             : #ifdef AUTOSELECT_USERFILTER
     789             :             if ( createNewUserFilter( _rFilter, sal_True ) )
     790             : #else
     791           0 :             if ( createNewUserFilter( _rFilter, false ) )
     792             : #endif
     793             :             {   // it's the "all files" filter
     794           0 :                 nReturn |= FLT_ALLFILESFILTER;
     795             : 
     796             : #ifdef AUTOSELECT_USERFILTER
     797             :                 // select the "all files" entry
     798             :                 OUString sAllFilesFilter( SvtResId( STR_FILTERNAME_ALL ) );
     799             :                 if ( _pImp->HasFilterListEntry( sAllFilesFilter ) )
     800             :                 {
     801             :                     _pImp->SelectFilterListEntry( sAllFilesFilter );
     802             :                     _pImp->SetCurFilter( _pImp->GetSelectedFilterEntry( sAllFilesFilter ) );
     803             :                 }
     804             :                 else
     805             :                     _pImp->SetNoFilterListSelection( ); // there is no "all files" entry
     806             : #endif // AUTOSELECT_USERFILTER
     807             :             }
     808             : #ifdef AUTOSELECT_USERFILTER
     809             :             else
     810             :                 _pImp->SetNoFilterListSelection( );
     811             : #endif // AUTOSELECT_USERFILTER
     812             :         }
     813             :     }
     814             : 
     815           0 :     return nReturn;
     816             : }
     817             : 
     818             : 
     819           0 : IMPL_LINK_NOARG(SvtFileDialog, CancelHdl_Impl)
     820             : {
     821           0 :     if ( m_pCurrentAsyncAction.is() )
     822             :     {
     823           0 :         m_pCurrentAsyncAction->cancel();
     824           0 :         onAsyncOperationFinished();
     825             :     }
     826             :     else
     827             :     {
     828           0 :         EndDialog( RET_CANCEL );
     829             :     }
     830           0 :     return 1L;
     831             : }
     832             : 
     833             : 
     834           0 : IMPL_LINK( SvtFileDialog, OpenHdl_Impl, void*, pVoid )
     835             : {
     836           0 :     if ( _pImp->_bMultiSelection && _pFileView->GetSelectionCount() > 1 )
     837             :     {
     838             :         // special open in case of multiselection
     839           0 :         OpenMultiSelection_Impl();
     840           0 :         return 0;
     841             :     }
     842             : 
     843           0 :     OUString aFileName;
     844           0 :     OUString aOldPath( _pFileView->GetViewURL() );
     845           0 :     if ( _pImp->_bDoubleClick || _pFileView->HasChildPathFocus() )
     846             :         // Selection done by doubleclicking in the view, get filename from the view
     847           0 :         aFileName = _pFileView->GetCurrentURL();
     848             : 
     849           0 :     if ( aFileName.isEmpty() )
     850             :     {
     851             :         // if an entry is selected in the view ....
     852           0 :         if ( _pFileView->GetSelectionCount() )
     853             :         {   // -> use this one. This will allow us to step down this folder
     854           0 :             aFileName = _pFileView->GetCurrentURL();
     855             :         }
     856             :     }
     857             : 
     858           0 :     if ( aFileName.isEmpty() )
     859             :     {
     860           0 :         if ( _pImp->_eMode == FILEDLG_MODE_OPEN && _pImp->_pEdFileName->IsTravelSelect() )
     861             :             // OpenHdl called from URLBox; travelling through the list of URLs should not cause an opening
     862           0 :             return 0;                   // MBA->PB: seems to be called never ?!
     863             : 
     864             :         // get the URL from the edit field ( if not empty )
     865           0 :         if ( !_pImp->_pEdFileName->GetText().isEmpty() )
     866             :         {
     867           0 :             OUString aText = _pImp->_pEdFileName->GetText();
     868             : 
     869             :             // did we reach the root?
     870           0 :             if ( !INetURLObject( aOldPath ).getSegmentCount() )
     871             :             {
     872           0 :                 if ( ( aText.getLength() == 2 && aText == ".." ) ||
     873           0 :                      ( aText.getLength() == 3 && ( aText == "..\\" || aText == "../" ) ) )
     874             :                     // don't go higher than the root
     875           0 :                     return 0;
     876             :             }
     877             : 
     878             : #if defined( UNX )
     879           0 :             if ( ( 1 == aText.getLength() ) && ( '~' == aText[0] ) )
     880             :             {
     881             :                 // go to the home directory
     882           0 :                 if ( lcl_getHomeDirectory( _pFileView->GetViewURL(), aFileName ) )
     883             :                     // in case we got a home dir, reset the text of the edit
     884           0 :                     _pImp->_pEdFileName->SetText( OUString() );
     885             :             }
     886           0 :             if ( aFileName.isEmpty() )
     887             : #endif
     888             :             {
     889             :                 // get url from autocomplete edit
     890           0 :                 aFileName = _pImp->_pEdFileName->GetURL();
     891           0 :             }
     892             :         }
     893           0 :         else if ( pVoid == _pImp->_pBtnFileOpen )
     894             :             // OpenHdl was called for the "Open" Button; if edit field is empty, use selected element in the view
     895           0 :             aFileName = _pFileView->GetCurrentURL();
     896             :     }
     897             : 
     898             :     // MBA->PB: ?!
     899           0 :     if ( aFileName.isEmpty() && pVoid == _pImp->_pEdFileName && _pImp->_pUserFilter )
     900             :     {
     901           0 :         DELETEZ( _pImp->_pUserFilter );
     902           0 :         return 0;
     903             :     }
     904             : 
     905           0 :     sal_Int32 nLen = aFileName.getLength();
     906           0 :     if ( !nLen )
     907             :     {
     908             :         // if the dialog was opened to select a folder, the last selected folder should be selected
     909           0 :         if( _pImp->_eDlgType == FILEDLG_TYPE_PATHDLG )
     910             :         {
     911           0 :             aFileName = _pImp->_pEdCurrentPath->GetText();
     912           0 :             nLen = aFileName.getLength();
     913             :         }
     914             :         else
     915             :             // no file selected !
     916           0 :             return 0;
     917             :     }
     918             : 
     919             :     // mark input as selected
     920           0 :     _pImp->_pEdFileName->SetSelection( Selection( 0, nLen ) );
     921             : 
     922             :     // if a path with wildcards is given, divide the string into path and wildcards
     923           0 :     OUString aFilter;
     924           0 :     if ( !SvtFileDialog::IsolateFilterFromPath_Impl( aFileName, aFilter ) )
     925           0 :         return 0;
     926             : 
     927             :     // if a filter was retrieved, there were wildcards !
     928           0 :     sal_uInt16 nNewFilterFlags = adjustFilter( aFilter );
     929           0 :     if ( nNewFilterFlags & FLT_CHANGED )
     930             :     {
     931             :         // cut off all text before wildcard in edit and select wildcard
     932           0 :         _pImp->_pEdFileName->SetText( aFilter );
     933           0 :         _pImp->_pEdFileName->SetSelection( Selection( 0, aFilter.getLength() ) );
     934             :     }
     935             : 
     936             :     {
     937           0 :         INetURLObject aFileObject( aFileName );
     938           0 :         if ( ( aFileObject.GetProtocol() == INetProtocol::NotValid ) && !aFileName.isEmpty() )
     939             :         {
     940           0 :             OUString sCompleted = SvtURLBox::ParseSmart( aFileName, _pFileView->GetViewURL(), SvtPathOptions().GetWorkPath() );
     941           0 :             if ( !sCompleted.isEmpty() )
     942           0 :                 aFileName = sCompleted;
     943           0 :         }
     944             :     }
     945             : 
     946             :     // check if it is a folder
     947           0 :     bool bIsFolder = false;
     948             : 
     949             :     // first thing before doing anyhing with the content: Reset it. When the user presses "open" (or "save" or "export",
     950             :     // for that matter), s/he wants the complete handling, including all possible error messages, even if s/he
     951             :     // does the same thing for the same content twice, s/he wants both fails to be displayed.
     952             :     // Without the reset, it could be that the content cached all relevant information, and will not display any
     953             :     // error messages for the same content a second time ....
     954           0 :     m_aContent.bindTo( OUString( ) );
     955             : 
     956           0 :     if ( !aFileName.isEmpty() )
     957             :     {
     958             :         // Make sure we have own Interaction Handler in place. We do not need
     959             :         // to intercept interactions here, but to record the fact that there
     960             :         // was an interaction.
     961             :         SmartContent::InteractionHandlerType eInterActionHandlerType
     962           0 :             = m_aContent.queryCurrentInteractionHandler();
     963           0 :         if ( ( eInterActionHandlerType == SmartContent::IHT_NONE ) ||
     964             :              ( eInterActionHandlerType == SmartContent::IHT_DEFAULT ) )
     965             :             m_aContent.enableOwnInteractionHandler(
     966           0 :                 OFilePickerInteractionHandler::E_NOINTERCEPTION );
     967             : 
     968           0 :         bIsFolder = m_aContent.isFolder( aFileName );
     969             : 
     970             :         // access denied to the given resource - and interaction was already
     971             :         // used => break following operations
     972             :         OFilePickerInteractionHandler* pHandler
     973           0 :             = m_aContent.getOwnInteractionHandler();
     974             : 
     975             :         OSL_ENSURE( pHandler, "Got no Interaction Handler!!!" );
     976             : 
     977           0 :         if ( pHandler->wasAccessDenied() )
     978           0 :             return 0;
     979             : 
     980           0 :         if ( m_aContent.isInvalid() &&
     981           0 :              ( _pImp->_eMode == FILEDLG_MODE_OPEN ) )
     982             :         {
     983           0 :             if ( !pHandler->wasUsed() )
     984           0 :                 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS );
     985             : 
     986           0 :             return 0;
     987             :         }
     988             : 
     989             :         // restore previous Interaction Handler
     990           0 :         if ( eInterActionHandlerType == SmartContent::IHT_NONE )
     991           0 :             m_aContent.disableInteractionHandler();
     992           0 :         else if ( eInterActionHandlerType == SmartContent::IHT_DEFAULT )
     993           0 :             m_aContent.enableDefaultInteractionHandler();
     994             :      }
     995             : 
     996           0 :     if  (   !bIsFolder                                      // no existent folder
     997           0 :         &&  _pImp->_pCbAutoExtension                 // auto extension is enabled in general
     998           0 :         &&  _pImp->_pCbAutoExtension->IsChecked()    // auto extension is really to be used
     999           0 :         &&  !GetDefaultExt().isEmpty()               // there is a default extension
    1000           0 :         &&  !comphelper::string::equals(GetDefaultExt(), '*') // the default extension is not "all"
    1001           0 :         && !(   FILEDLG_MODE_SAVE == _pImp->_eMode       // we're saving a file
    1002           0 :             &&  _pFileView->GetSelectionCount()          // there is a selected file in the file view -> it will later on
    1003           0 :             )                                                   //    (in SvtFileDialog::GetPathList) be taken as file to save to
    1004             : 
    1005           0 :         && FILEDLG_MODE_OPEN != _pImp->_eMode // #i83408# don't append extension on open
    1006             :         )
    1007             :     {
    1008             :         // check extension and append the default extension if necessary
    1009             :         appendDefaultExtension(aFileName,
    1010           0 :                                GetDefaultExt(),
    1011           0 :                                _pImp->GetCurFilter()->GetType());
    1012             :     }
    1013             : 
    1014           0 :     bool bOpenFolder = ( FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType ) &&
    1015           0 :                        !_pImp->_bDoubleClick && pVoid != _pImp->_pEdFileName;
    1016           0 :     if ( bIsFolder )
    1017             :     {
    1018           0 :         if ( bOpenFolder )
    1019             :         {
    1020           0 :             _aPath = aFileName;
    1021             :         }
    1022             :         else
    1023             :         {
    1024           0 :             if ( aFileName != _pFileView->GetViewURL() )
    1025             :             {
    1026           0 :                 OpenURL_Impl( aFileName );
    1027             :             }
    1028             :             else
    1029             :             {
    1030           0 :                 if ( nNewFilterFlags & FLT_CHANGED )
    1031           0 :                     ExecuteFilter();
    1032             :             }
    1033             : 
    1034           0 :             return 0;
    1035             :         }
    1036             :     }
    1037           0 :     else if ( !( nNewFilterFlags & FLT_NONEMPTY ) )
    1038             :     {
    1039             :         // if applicable save URL
    1040           0 :         _aPath = aFileName;
    1041             :     }
    1042             :     else
    1043             :     {
    1044             :         // if applicable filter again
    1045           0 :         if ( nNewFilterFlags & FLT_CHANGED )
    1046           0 :             ExecuteFilter();
    1047           0 :         return 0;
    1048             :     }
    1049             : 
    1050           0 :     INetURLObject aFileObj( aFileName );
    1051           0 :     if ( aFileObj.HasError() )
    1052             :     {
    1053           0 :         ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
    1054           0 :         return 0;
    1055             :     }
    1056             : 
    1057           0 :     switch ( _pImp->_eMode )
    1058             :     {
    1059             :         case FILEDLG_MODE_SAVE:
    1060             :         {
    1061           0 :             if ( ::utl::UCBContentHelper::Exists( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
    1062             :             {
    1063           0 :                 OUString aMsg = SVT_RESSTR( STR_SVT_ALREADYEXISTOVERWRITE );
    1064           0 :                 aMsg = aMsg.replaceFirst(
    1065             :                     "$filename$",
    1066             :                     aFileObj.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET)
    1067           0 :                 );
    1068           0 :                 ScopedVclPtrInstance< MessageDialog > aBox(this, aMsg, VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
    1069           0 :                 if ( aBox->Execute() != RET_YES )
    1070           0 :                     return 0;
    1071             :             }
    1072             :             else
    1073             :             {
    1074           0 :                 OUString aCurPath;
    1075           0 :                 if ( ::utl::LocalFileHelper::ConvertURLToSystemPath( aFileName, aCurPath ) )
    1076             :                 {
    1077             :                     // if content does not exist: at least its path must exist
    1078           0 :                     INetURLObject aPathObj = aFileObj;
    1079           0 :                     aPathObj.removeSegment();
    1080           0 :                     bool bFolder = m_aContent.isFolder( aPathObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1081           0 :                     if ( !bFolder )
    1082             :                     {
    1083           0 :                         ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH );
    1084           0 :                         return 0;
    1085           0 :                     }
    1086           0 :                 }
    1087             :             }
    1088             :         }
    1089           0 :         break;
    1090             : 
    1091             :         case FILEDLG_MODE_OPEN:
    1092             :         {
    1093             :             // do an existence check herein, again
    1094             : 
    1095           0 :             if ( INetProtocol::File == aFileObj.GetProtocol( ) )
    1096             :             {
    1097           0 :                 bool bExists = m_aContent.is( aFileObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1098             : 
    1099           0 :                 if ( !bExists )
    1100             :                 {
    1101           0 :                     OUString sError( SVT_RESSTR( RID_FILEOPEN_NOTEXISTENTFILE ) );
    1102             : 
    1103           0 :                     OUString sInvalidFile( aFileObj.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
    1104           0 :                     if ( INetProtocol::File == aFileObj.GetProtocol() )
    1105             :                     {   // if it's a file URL, transform the URL into system notation
    1106           0 :                         OUString sURL( sInvalidFile );
    1107           0 :                         OUString sSystem;
    1108           0 :                         osl_getSystemPathFromFileURL( sURL.pData, &sSystem.pData );
    1109           0 :                         sInvalidFile = sSystem;
    1110             :                     }
    1111           0 :                     sError = sError.replaceFirst( "$name$", sInvalidFile );
    1112             : 
    1113           0 :                     ScopedVclPtrInstance< MessageDialog > aError(this, sError);
    1114           0 :                     aError->Execute();
    1115           0 :                     return 0;
    1116             :                 }
    1117             :             }
    1118             :         }
    1119           0 :         break;
    1120             : 
    1121             :         default:
    1122             :             OSL_FAIL("SvtFileDialog, OpenHdl_Impl: invalid mode!");
    1123             :     }
    1124             : 
    1125             :     // notify interested parties
    1126             :     long nRet;
    1127             : 
    1128           0 :     if ( _aOKHdl.IsSet() )
    1129           0 :         nRet = _aOKHdl.Call( this );
    1130             :     else
    1131           0 :         nRet = 1;
    1132             : 
    1133           0 :     if ( nRet )
    1134             :     {
    1135           0 :         EndDialog( RET_OK );
    1136             :     }
    1137             : 
    1138           0 :     return nRet;
    1139             : }
    1140             : 
    1141             : 
    1142             : 
    1143           0 : void SvtFileDialog::EnableAutocompletion( bool _bEnable )
    1144             : {
    1145           0 :     _pImp->_pEdFileName->EnableAutocompletion( _bEnable );
    1146           0 : }
    1147             : 
    1148             : 
    1149             : 
    1150           0 : IMPL_LINK_NOARG( SvtFileDialog, FilterSelectHdl_Impl )
    1151             : {
    1152           0 :     OUString sSelectedFilterDisplayName;
    1153           0 :     SvtFileDialogFilter_Impl* pSelectedFilter = _pImp->GetSelectedFilterEntry( sSelectedFilterDisplayName );
    1154           0 :     if ( !pSelectedFilter )
    1155             :     {   // there is no current selection. This happens if for instance the user selects a group separator using
    1156             :         // the keyboard, and then presses enter: When the selection happens, we immediately deselect the entry,
    1157             :         // so in this situation there is no current selection.
    1158           0 :         if ( restoreCurrentFilter( _pImp ) )
    1159           0 :             ExecuteFilter();
    1160             :     }
    1161             :     else
    1162             :     {
    1163           0 :         if ( pSelectedFilter->isGroupSeparator() )
    1164             :         {   // group separators can't be selected
    1165             :             // return to the previously selected entry
    1166           0 :             if ( _pImp->IsFilterListTravelSelect() )
    1167             :             {
    1168           0 :                 _pImp->SetNoFilterListSelection( );
    1169             : 
    1170             :                 // stop the timer for executing the filter
    1171           0 :                 if ( _pImp->_aFilterTimer.IsActive() )
    1172           0 :                     _pImp->m_bNeedDelayedFilterExecute = true;
    1173           0 :                 _pImp->_aFilterTimer.Stop();
    1174             :             }
    1175             :             else
    1176             :             {
    1177           0 :                 if ( restoreCurrentFilter( _pImp ) )
    1178           0 :                     ExecuteFilter();
    1179             :             }
    1180             :         }
    1181           0 :         else if (   ( pSelectedFilter != _pImp->GetCurFilter() )
    1182           0 :                 ||  _pImp->_pUserFilter
    1183             :                 )
    1184             :         {
    1185             :             // Store the old filter for the auto extension handling
    1186           0 :             OUString sLastFilterExt = _pImp->GetCurFilter()->GetExtension();
    1187           0 :             DELETEZ( _pImp->_pUserFilter );
    1188             : 
    1189             :             // if applicable remove filter of the user
    1190           0 :             _pImp->SetCurFilter( pSelectedFilter, sSelectedFilterDisplayName );
    1191             : 
    1192             :             // if applicable show extension
    1193           0 :             SetDefaultExt( pSelectedFilter->GetExtension() );
    1194           0 :             sal_Int32 nSepPos = GetDefaultExt().indexOf( FILEDIALOG_DEF_EXTSEP );
    1195             : 
    1196           0 :             if ( nSepPos != -1 )
    1197           0 :                 EraseDefaultExt( nSepPos );
    1198             : 
    1199             :             // update the extension of the current file if necessary
    1200           0 :             lcl_autoUpdateFileExtension( this, sLastFilterExt );
    1201             : 
    1202             :             // if the user is traveling fast through the filterbox
    1203             :             // do not filter instantly
    1204           0 :             if ( _pImp->IsFilterListTravelSelect() )
    1205             :             {
    1206             :                 // FilterSelectHdl_Impl should be started again in
    1207             :                 // TRAVELFILTER_TIMEOUT ms
    1208           0 :                 _pImp->_aFilterTimer.Start();
    1209             :             }
    1210             :             else
    1211             :             {
    1212             :                 // stop previously started timer
    1213           0 :                 _pImp->_aFilterTimer.Stop();
    1214             : 
    1215             :                 // filter the view again
    1216           0 :                 ExecuteFilter();
    1217           0 :             }
    1218             :         }
    1219             :     }
    1220             : 
    1221           0 :     return 0;
    1222             : }
    1223             : 
    1224           0 : IMPL_LINK_NOARG_TYPED(SvtFileDialog, FilterSelectTimerHdl_Impl, Timer*, void)
    1225             : {
    1226             :     // filter the view again
    1227           0 :     ExecuteFilter();
    1228           0 : }
    1229             : 
    1230           0 : IMPL_LINK_NOARG( SvtFileDialog, FileNameGetFocusHdl_Impl )
    1231             : {
    1232           0 :     _pFileView->SetNoSelection();
    1233           0 :     _pFileView->Update();
    1234           0 :     return 0;
    1235             : }
    1236             : 
    1237             : 
    1238             : 
    1239           0 : IMPL_LINK_NOARG( SvtFileDialog, FileNameModifiedHdl_Impl )
    1240             : {
    1241           0 :     FileNameGetFocusHdl_Impl( NULL );
    1242           0 :     return 0;
    1243             : }
    1244             : 
    1245             : 
    1246             : 
    1247           0 : IMPL_LINK_NOARG( SvtFileDialog, URLBoxModifiedHdl_Impl )
    1248             : {
    1249           0 :     OUString aPath = _pImp->_pEdCurrentPath->GetURL();
    1250           0 :     OpenURL_Impl(aPath);
    1251           0 :     return 0;
    1252             : }
    1253             : 
    1254             : 
    1255             : 
    1256           0 : IMPL_LINK_NOARG( SvtFileDialog, ConnectToServerPressed_Hdl )
    1257             : {
    1258           0 :     _pFileView->EndInplaceEditing( false );
    1259             : 
    1260           0 :     ScopedVclPtrInstance< PlaceEditDialog > aDlg(this);
    1261           0 :     short aRetCode = aDlg->Execute();
    1262             : 
    1263           0 :     switch (aRetCode) {
    1264             :         case RET_OK :
    1265             :         {
    1266           0 :             PlacePtr newPlace = aDlg->GetPlace();
    1267           0 :             _pImp->_pPlaces->AppendPlace(newPlace);
    1268             : 
    1269           0 :       break;
    1270             :         }
    1271             :         case RET_CANCEL :
    1272             :         default :
    1273             :             // Do Nothing
    1274           0 :             break;
    1275             :     };
    1276             : 
    1277           0 :     return 0;
    1278             : }
    1279             : 
    1280             : 
    1281             : 
    1282           0 : IMPL_LINK_NOARG ( SvtFileDialog, AddPlacePressed_Hdl )
    1283             : {
    1284             :     // Maybe open the PlacesDialog would have been a better idea
    1285             :     // there is an ux choice to make we did not make...
    1286           0 :     INetURLObject aURLObj( _pFileView->GetViewURL() );
    1287             :     PlacePtr newPlace(
    1288             :         new Place( aURLObj.GetLastName(INetURLObject::DECODE_WITH_CHARSET),
    1289           0 :                 OUString(_pFileView->GetViewURL()), true));
    1290           0 :     _pImp->_pPlaces->AppendPlace(newPlace);
    1291           0 :     return 0;
    1292             : }
    1293             : 
    1294             : 
    1295             : 
    1296           0 : IMPL_LINK_NOARG ( SvtFileDialog, RemovePlacePressed_Hdl )
    1297             : {
    1298           0 :     _pImp->_pPlaces->RemoveSelectedPlace();
    1299           0 :     return 0;
    1300             : }
    1301             : 
    1302             : 
    1303             : 
    1304           0 : SvtFileDialogFilter_Impl* SvtFileDialog::FindFilter_Impl
    1305             : (
    1306             :     const OUString& _rFilter,
    1307             :     bool _bMultiExt,/*  TRUE - regard filter with several extensions
    1308             :                             FALSE - do not ...
    1309             :                         */
    1310             :     bool& _rFilterChanged
    1311             : )
    1312             : 
    1313             : /*  [Description]
    1314             : 
    1315             :     This method looks for the specified extension in the included filters.
    1316             : */
    1317             : 
    1318             : {
    1319           0 :     SvtFileDialogFilter_Impl* pFoundFilter = NULL;
    1320           0 :     SvtFileDialogFilterList_Impl* pList = _pImp->_pFilter;
    1321           0 :     sal_uInt16 nFilter = pList->size();
    1322             : 
    1323           0 :     while ( nFilter-- )
    1324             :     {
    1325           0 :         SvtFileDialogFilter_Impl* pFilter = &(*pList)[ nFilter ];
    1326           0 :         const OUString& rType = pFilter->GetType();
    1327           0 :         OUString aSingleType = rType;
    1328             : 
    1329           0 :         if ( _bMultiExt )
    1330             :         {
    1331           0 :             sal_Int32 nIdx = 0;
    1332           0 :             while ( !pFoundFilter && nIdx != -1 )
    1333             :             {
    1334           0 :                 aSingleType = rType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nIdx );
    1335             : #ifdef UNX
    1336           0 :                 if ( aSingleType == _rFilter )
    1337             : #else
    1338             :                 if ( aSingleType.equalsIgnoreAsciiCase( _rFilter ) )
    1339             : #endif
    1340           0 :                     pFoundFilter = pFilter;
    1341             :             }
    1342             :         }
    1343             : #ifdef UNX
    1344           0 :         else if ( rType == _rFilter )
    1345             : #else
    1346             :         else if ( rType.equalsIgnoreAsciiCase( _rFilter ) )
    1347             : #endif
    1348           0 :             pFoundFilter = pFilter;
    1349             : 
    1350           0 :         if ( pFoundFilter )
    1351             :         {
    1352             :             // activate filter
    1353           0 :             _rFilterChanged = _pImp->_pUserFilter || ( _pImp->GetCurFilter() != pFilter );
    1354             : 
    1355           0 :             createNewUserFilter( _rFilter, false );
    1356             : 
    1357           0 :             break;
    1358             :         }
    1359           0 :     }
    1360           0 :     return pFoundFilter;
    1361             : }
    1362             : 
    1363             : 
    1364             : 
    1365           0 : void SvtFileDialog::ExecuteFilter()
    1366             : {
    1367           0 :     _pImp->m_bNeedDelayedFilterExecute = false;
    1368           0 :     executeAsync( AsyncPickerAction::eExecuteFilter, OUString(), getMostCurrentFilter( _pImp ) );
    1369           0 : }
    1370             : 
    1371             : 
    1372             : 
    1373           0 : void SvtFileDialog::OpenMultiSelection_Impl()
    1374             : 
    1375             : /*  [Description]
    1376             : 
    1377             :     OpenHandler for MultiSelection
    1378             : */
    1379             : 
    1380             : {
    1381           0 :     sal_uLong nCount = _pFileView->GetSelectionCount();
    1382           0 :     SvTreeListEntry* pEntry = nCount ? _pFileView->FirstSelected() : NULL;
    1383             : 
    1384           0 :     if ( nCount && pEntry )
    1385           0 :         _aPath = SvtFileView::GetURL( pEntry );
    1386             : 
    1387             :     // notify interested parties
    1388             :     long nRet;
    1389             : 
    1390           0 :     if ( _aOKHdl.IsSet() )
    1391           0 :         nRet = _aOKHdl.Call( this );
    1392             :     else
    1393           0 :         nRet = 1;
    1394             : 
    1395           0 :     if ( nRet )
    1396           0 :         EndDialog( RET_OK );
    1397           0 : }
    1398             : 
    1399             : 
    1400             : 
    1401           0 : void SvtFileDialog::UpdateControls( const OUString& rURL )
    1402             : {
    1403           0 :        _pImp->_pEdFileName->SetBaseURL( rURL );
    1404             : 
    1405           0 :     INetURLObject aObj( rURL );
    1406             : 
    1407             : 
    1408             :     {
    1409           0 :         OUString sText;
    1410             :         DBG_ASSERT( INetProtocol::NotValid != aObj.GetProtocol(), "SvtFileDialog::UpdateControls: Invalid URL!" );
    1411             : 
    1412           0 :         if ( aObj.getSegmentCount() )
    1413             :         {
    1414           0 :             ::utl::LocalFileHelper::ConvertURLToSystemPath( rURL, sText );
    1415           0 :             if ( !sText.isEmpty() )
    1416             :             {
    1417             :                 // no Fsys path for server file system ( only UCB has mountpoints! )
    1418           0 :                 if ( INetProtocol::File != aObj.GetProtocol() )
    1419           0 :                     sText = rURL.copy( INetURLObject::GetScheme( aObj.GetProtocol() ).getLength() );
    1420             :             }
    1421             : 
    1422           0 :             if ( sText.isEmpty() && aObj.getSegmentCount() )
    1423           0 :                 sText = rURL;
    1424             :         }
    1425             : 
    1426             :         // path mode ?
    1427           0 :         if ( FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType )
    1428             :             // -> set new path in the edit field
    1429           0 :             _pImp->_pEdFileName->SetText( sText );
    1430             : 
    1431             :         // in the "current path" field, truncate the trailing slash
    1432           0 :         if ( aObj.hasFinalSlash() )
    1433             :         {
    1434           0 :             aObj.removeFinalSlash();
    1435           0 :             OUString sURL( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1436           0 :             if ( !::utl::LocalFileHelper::ConvertURLToSystemPath( sURL, sText ) )
    1437           0 :                 sText = sURL;
    1438             :         }
    1439             : 
    1440           0 :         if ( sText.isEmpty() && !rURL.isEmpty() )
    1441             :             // happens, for instance, for URLs which the INetURLObject does not know to belong to a hierarchical scheme
    1442           0 :             sText = rURL;
    1443           0 :         _pImp->_pEdCurrentPath->SetText( sText );
    1444             :     }
    1445             : 
    1446             : 
    1447           0 :     _aPath = rURL;
    1448           0 :     if ( _pFileNotifier )
    1449           0 :         _pFileNotifier->notify( DIRECTORY_CHANGED, 0 );
    1450           0 : }
    1451             : 
    1452             : 
    1453             : 
    1454           0 : IMPL_LINK( SvtFileDialog, SelectHdl_Impl, SvTabListBox*, pBox )
    1455             : {
    1456           0 :     SvTreeListEntry* pEntry = pBox->FirstSelected();
    1457             :     DBG_ASSERT( pEntry, "SelectHandler without selected entry" );
    1458           0 :     SvtContentEntry* pUserData = static_cast<SvtContentEntry*>(pEntry->GetUserData());
    1459             : 
    1460           0 :     if ( pUserData )
    1461             :     {
    1462           0 :         INetURLObject aObj( pUserData->maURL );
    1463           0 :         if ( FILEDLG_TYPE_PATHDLG == _pImp->_eDlgType )
    1464             :         {
    1465           0 :             if ( aObj.GetProtocol() == INetProtocol::File )
    1466             :             {
    1467           0 :                 if ( !pUserData->mbIsFolder )
    1468           0 :                     aObj.removeSegment();
    1469           0 :                 OUString aName = aObj.getFSysPath( (INetURLObject::FSysStyle)(INetURLObject::FSYS_DETECT & ~INetURLObject::FSYS_VOS) );
    1470           0 :                 _pImp->_pEdFileName->SetText( aName );
    1471           0 :                 _pImp->_pEdFileName->SetSelection( Selection( 0, aName.getLength() ) );
    1472           0 :                 _aPath = pUserData->maURL;
    1473             :             }
    1474           0 :             else if ( !pUserData->mbIsFolder )
    1475             :             {
    1476           0 :                 _pImp->_pEdFileName->SetText( pUserData->maURL );
    1477           0 :                 _pImp->_pEdFileName->SetSelection( Selection( 0, pUserData->maURL.getLength() ) );
    1478           0 :                 _aPath = pUserData->maURL;
    1479             :             }
    1480             :             else
    1481           0 :                 _pImp->_pEdFileName->SetText( OUString() );
    1482             :         }
    1483             :         else
    1484             :         {
    1485           0 :             if ( !pUserData->mbIsFolder )
    1486             :             {
    1487           0 :                 OUString aName = SvTabListBox::GetEntryText( pEntry, 0 );
    1488           0 :                 _pImp->_pEdFileName->SetText( aName );
    1489           0 :                 _pImp->_pEdFileName->SetSelection( Selection( 0, aName.getLength() ) );
    1490           0 :                 _aPath = pUserData->maURL;
    1491             :             }
    1492           0 :         }
    1493             :     }
    1494             : 
    1495           0 :     if ( _pImp->_bMultiSelection && _pFileView->GetSelectionCount() > 1 )
    1496             :     {
    1497             :         // clear the file edit for multiselection
    1498           0 :         _pImp->_pEdFileName->SetText( OUString() );
    1499             :     }
    1500             : 
    1501           0 :     FileSelect();
    1502             : 
    1503           0 :     return 0;
    1504             : }
    1505             : 
    1506             : 
    1507             : 
    1508           0 : IMPL_LINK_NOARG(SvtFileDialog, DblClickHdl_Impl)
    1509             : {
    1510           0 :     _pImp->_bDoubleClick = true;
    1511           0 :     OpenHdl_Impl( NULL );
    1512           0 :     _pImp->_bDoubleClick = false;
    1513             : 
    1514           0 :     return 0;
    1515             : }
    1516             : 
    1517             : 
    1518             : 
    1519           0 : IMPL_LINK_NOARG(SvtFileDialog, EntrySelectHdl_Impl)
    1520             : {
    1521           0 :     FileSelect();
    1522             : 
    1523           0 :     return 0;
    1524             : }
    1525             : 
    1526             : 
    1527             : 
    1528           0 : IMPL_LINK( SvtFileDialog, OpenDoneHdl_Impl, SvtFileView*, pView )
    1529             : {
    1530           0 :     OUString sCurrentFolder( pView->GetViewURL() );
    1531             :     // check if we can create new folders
    1532           0 :     EnableControl( _pImp->_pBtnNewFolder, ContentCanMakeFolder( sCurrentFolder ) );
    1533             : 
    1534             :     // check if we can travel one level up
    1535           0 :     bool bCanTravelUp = ContentHasParentFolder( pView->GetViewURL() );
    1536           0 :     if ( bCanTravelUp )
    1537             :     {
    1538             :         // additional check: the parent folder should not be prohibited
    1539           0 :         INetURLObject aCurrentFolder( sCurrentFolder );
    1540             :         DBG_ASSERT( INetProtocol::NotValid != aCurrentFolder.GetProtocol(),
    1541             :             "SvtFileDialog::OpenDoneHdl_Impl: invalid current URL!" );
    1542             : 
    1543           0 :         aCurrentFolder.removeSegment();
    1544             :     }
    1545           0 :     EnableControl( _pImp->_pBtnUp, bCanTravelUp );
    1546             : 
    1547           0 :     return 0;
    1548             : }
    1549             : 
    1550             : 
    1551             : 
    1552           0 : IMPL_LINK_NOARG(SvtFileDialog, AutoExtensionHdl_Impl)
    1553             : {
    1554           0 :     if ( _pFileNotifier )
    1555             :         _pFileNotifier->notify( CTRL_STATE_CHANGED,
    1556           0 :                                 CHECKBOX_AUTOEXTENSION );
    1557             : 
    1558             :     // update the extension of the current file if necessary
    1559           0 :     lcl_autoUpdateFileExtension( this, _pImp->GetCurFilter()->GetExtension() );
    1560             : 
    1561           0 :     return 0;
    1562             : }
    1563             : 
    1564             : 
    1565             : 
    1566           0 : IMPL_LINK( SvtFileDialog, ClickHdl_Impl, CheckBox*, pCheckBox )
    1567             : {
    1568           0 :     if ( ! _pFileNotifier )
    1569           0 :         return 0;
    1570             : 
    1571           0 :     sal_Int16 nId = -1;
    1572             : 
    1573           0 :     if ( pCheckBox == _pImp->_pCbOptions )
    1574           0 :         nId = CHECKBOX_FILTEROPTIONS;
    1575           0 :     else if ( pCheckBox == _pCbSelection )
    1576           0 :         nId = CHECKBOX_SELECTION;
    1577           0 :     else if ( pCheckBox == _pCbReadOnly )
    1578           0 :         nId = CHECKBOX_READONLY;
    1579           0 :     else if ( pCheckBox == _pImp->_pCbPassword )
    1580           0 :         nId = CHECKBOX_PASSWORD;
    1581           0 :     else if ( pCheckBox == _pCbLinkBox )
    1582           0 :         nId = CHECKBOX_LINK;
    1583           0 :     else if ( pCheckBox == _pCbPreviewBox )
    1584           0 :         nId = CHECKBOX_PREVIEW;
    1585             : 
    1586           0 :     if ( nId != -1 )
    1587           0 :         _pFileNotifier->notify( CTRL_STATE_CHANGED, nId );
    1588             : 
    1589           0 :     return 0;
    1590             : }
    1591             : 
    1592             : 
    1593             : 
    1594           0 : IMPL_LINK_NOARG(SvtFileDialog, PlayButtonHdl_Impl)
    1595             : {
    1596           0 :     if ( _pFileNotifier )
    1597             :         _pFileNotifier->notify( CTRL_STATE_CHANGED,
    1598           0 :                                 PUSHBUTTON_PLAY );
    1599             : 
    1600           0 :     return 0;
    1601             : }
    1602             : 
    1603             : 
    1604             : 
    1605           0 : bool SvtFileDialog::Notify( NotifyEvent& rNEvt )
    1606             : 
    1607             : /*  [Description]
    1608             : 
    1609             :     This method gets called to catch <BACKSPACE>.
    1610             : */
    1611             : 
    1612             : {
    1613           0 :     MouseNotifyEvent nType = rNEvt.GetType();
    1614           0 :     bool nRet = false;
    1615             : 
    1616           0 :     if ( MouseNotifyEvent::KEYINPUT == nType && rNEvt.GetKeyEvent() )
    1617             :     {
    1618           0 :         const vcl::KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
    1619           0 :         sal_uInt16 nCode = rKeyCode.GetCode();
    1620             : 
    1621           0 :         if ( !rKeyCode.GetModifier() &&
    1622           0 :              KEY_BACKSPACE == nCode && !_pImp->_pEdFileName->HasChildPathFocus() )
    1623             :         {
    1624           0 :             nRet = false;
    1625             : 
    1626           0 :             if ( !nRet && _pImp->_pBtnUp->IsEnabled() )
    1627             :             {
    1628           0 :                 PrevLevel_Impl();
    1629           0 :                 nRet = true;
    1630             :             }
    1631             :         }
    1632             :     }
    1633           0 :     return nRet || ModalDialog::Notify( rNEvt );
    1634             : }
    1635             : 
    1636             : 
    1637             : 
    1638             : class SvtDefModalDialogParent_Impl
    1639             : {
    1640             : private:
    1641             :     VclPtr<vcl::Window> _pOld;
    1642             : 
    1643             : public:
    1644           0 :     SvtDefModalDialogParent_Impl( vcl::Window *pNew ) :
    1645           0 :         _pOld( Application::GetDefDialogParent() )
    1646           0 :         { Application::SetDefDialogParent( pNew ); }
    1647             : 
    1648           0 :     ~SvtDefModalDialogParent_Impl() { Application::SetDefDialogParent( _pOld ); }
    1649             : };
    1650             : 
    1651             : namespace
    1652             : {
    1653             : 
    1654           0 : bool implIsInvalid( const OUString & rURL )
    1655             : {
    1656           0 :     SmartContent aContent( rURL );
    1657           0 :     aContent.enableOwnInteractionHandler( ::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST );
    1658           0 :     aContent.isFolder();    // do this _before_ asking isInvalid! Otherwise result might be wrong.
    1659           0 :     return aContent.isInvalid();
    1660             : }
    1661             : 
    1662             : }
    1663             : 
    1664             : 
    1665           0 : OUString SvtFileDialog::implGetInitialURL( const OUString& _rPath, const OUString& _rFallback )
    1666             : {
    1667             :     // an URL parser for the fallback
    1668           0 :     INetURLObject aURLParser;
    1669             : 
    1670             :     // set the path
    1671           0 :     bool bWasAbsolute = false;
    1672           0 :     aURLParser = aURLParser.smartRel2Abs( _rPath, bWasAbsolute );
    1673             : 
    1674             :     // is it a valid folder?
    1675           0 :     m_aContent.bindTo( aURLParser.GetMainURL( INetURLObject::NO_DECODE ) );
    1676           0 :     bool bIsFolder = m_aContent.isFolder( );    // do this _before_ asking isInvalid!
    1677           0 :     bool bIsInvalid = m_aContent.isInvalid();
    1678             : 
    1679           0 :     if ( bIsInvalid && m_bHasFilename && !aURLParser.hasFinalSlash() )
    1680             :     {   // check if the parent folder exists
    1681           0 :         INetURLObject aParent( aURLParser );
    1682           0 :         aParent.removeSegment( );
    1683           0 :         aParent.setFinalSlash( );
    1684           0 :         bIsInvalid = implIsInvalid( aParent.GetMainURL( INetURLObject::NO_DECODE ) );
    1685             :     }
    1686             : 
    1687           0 :     if ( bIsInvalid )
    1688             :     {
    1689           0 :         INetURLObject aFallback( _rFallback );
    1690           0 :         bIsInvalid = implIsInvalid( aFallback.GetMainURL( INetURLObject::NO_DECODE ) );
    1691             : 
    1692           0 :         if ( !bIsInvalid )
    1693           0 :             aURLParser = aFallback;
    1694             :     }
    1695             : 
    1696           0 :     if ( bIsInvalid )
    1697             :     {
    1698           0 :         INetURLObject aParent( aURLParser );
    1699           0 :         while ( bIsInvalid && aParent.removeSegment() )
    1700             :         {
    1701           0 :             aParent.setFinalSlash( );
    1702           0 :             bIsInvalid = implIsInvalid( aParent.GetMainURL( INetURLObject::NO_DECODE ) );
    1703             :         }
    1704             : 
    1705           0 :         if ( !bIsInvalid )
    1706           0 :             aURLParser = aParent;
    1707             :     }
    1708             : 
    1709           0 :     if ( !bIsInvalid && bIsFolder )
    1710             :     {
    1711           0 :         aURLParser.setFinalSlash();
    1712             :     }
    1713           0 :     return aURLParser.GetMainURL( INetURLObject::NO_DECODE );
    1714             : }
    1715             : 
    1716             : 
    1717           0 : short SvtFileDialog::Execute()
    1718             : {
    1719           0 :     if ( !PrepareExecute() )
    1720           0 :         return 0;
    1721             : 
    1722             :     // start the dialog
    1723           0 :     _bIsInExecute = true;
    1724           0 :     short nResult = ModalDialog::Execute();
    1725           0 :     _bIsInExecute = false;
    1726             : 
    1727             :     DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFilePicker::Execute: still running an async action!" );
    1728             :         // the dialog should not be cancellable while an async action is running - first, the action
    1729             :         // needs to be cancelled
    1730             : 
    1731             :     // remember last directory
    1732           0 :     if ( RET_OK == nResult )
    1733             :     {
    1734           0 :         INetURLObject aURL( _aPath );
    1735           0 :         if ( aURL.GetProtocol() == INetProtocol::File )
    1736             :         {
    1737             :             // remember the selected directory only for file URLs not for virtual folders
    1738           0 :             sal_Int32 nLevel = aURL.getSegmentCount();
    1739           0 :             bool bDir = m_aContent.isFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
    1740           0 :             if ( nLevel > 1 && ( FILEDLG_TYPE_FILEDLG == _pImp->_eDlgType || !bDir ) )
    1741           0 :                 aURL.removeSegment();
    1742           0 :         }
    1743             :     }
    1744             : 
    1745           0 :     return nResult;
    1746             : }
    1747             : 
    1748             : 
    1749           0 : void SvtFileDialog::StartExecuteModal( const Link<>& rEndDialogHdl )
    1750             : {
    1751           0 :     PrepareExecute();
    1752             : 
    1753             :     // start of the dialog
    1754           0 :     ModalDialog::StartExecuteModal( rEndDialogHdl );
    1755           0 : }
    1756             : 
    1757             : 
    1758           0 : void SvtFileDialog::onAsyncOperationStarted()
    1759             : {
    1760           0 :     EnableUI( false );
    1761             :     // the cancel button must be always enabled
    1762           0 :     _pImp->_pBtnCancel->Enable( true );
    1763           0 :     _pImp->_pBtnCancel->GrabFocus();
    1764           0 : }
    1765             : 
    1766             : 
    1767           0 : void SvtFileDialog::onAsyncOperationFinished()
    1768             : {
    1769           0 :     EnableUI( true );
    1770           0 :     m_pCurrentAsyncAction = NULL;
    1771           0 :     if ( !m_bInExecuteAsync )
    1772           0 :         _pImp->_pEdFileName->GrabFocus();
    1773             :         // (if m_bInExecuteAsync is true, then the operation was finished within the minium wait time,
    1774             :         // and to the user, the operation appears to be synchronous)
    1775           0 : }
    1776             : 
    1777             : 
    1778           0 : void SvtFileDialog::RemovablePlaceSelected(bool enable)
    1779             : {
    1780           0 :     _pImp->_pPlaces->SetDelEnabled( enable );
    1781           0 : }
    1782             : 
    1783             : 
    1784           0 : void SvtFileDialog::displayIOException( const OUString& _rURL, IOErrorCode _eCode )
    1785             : {
    1786             :     try
    1787             :     {
    1788             :         // create make a human-readable string from the URL
    1789           0 :         OUString sDisplayPath( _rURL );
    1790           0 :         ::utl::LocalFileHelper::ConvertURLToSystemPath( _rURL, sDisplayPath );
    1791             : 
    1792             :         // build an own exception which tells "access denied"
    1793           0 :         InteractiveAugmentedIOException aException;
    1794           0 :         aException.Arguments.realloc( 2 );
    1795           0 :         aException.Arguments[ 0 ] <<= sDisplayPath;
    1796           0 :         aException.Arguments[ 1 ] <<= PropertyValue(
    1797             :             OUString( "Uri" ),
    1798           0 :             -1, aException.Arguments[ 0 ], PropertyState_DIRECT_VALUE
    1799           0 :         );
    1800             :             // (formerly, it was sufficient to put the URL first parameter. Nowadays,
    1801             :             // the services expects the URL in a PropertyValue named "Uri" ...)
    1802           0 :         aException.Code = _eCode;
    1803           0 :         aException.Classification = InteractionClassification_ERROR;
    1804             : 
    1805             :         // let and interaction handler handle this exception
    1806           0 :         ::comphelper::OInteractionRequest* pRequest = NULL;
    1807             :         Reference< ::com::sun::star::task::XInteractionRequest > xRequest = pRequest =
    1808           0 :             new ::comphelper::OInteractionRequest( makeAny( aException ) );
    1809           0 :         pRequest->addContinuation( new ::comphelper::OInteractionAbort( ) );
    1810             : 
    1811             :         Reference< XInteractionHandler2 > xHandler(
    1812           0 :             InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), 0 ) );
    1813           0 :         xHandler->handle( xRequest );
    1814             :     }
    1815           0 :     catch( const Exception& )
    1816             :     {
    1817             :         OSL_FAIL( "iodlg::displayIOException: caught an exception!" );
    1818             :     }
    1819           0 : }
    1820             : 
    1821             : 
    1822           0 : void SvtFileDialog::EnableUI( bool _bEnable )
    1823             : {
    1824           0 :     Enable( _bEnable );
    1825             : 
    1826           0 :     if ( _bEnable )
    1827             :     {
    1828           0 :         for ( auto aLoop = m_aDisabledControls.begin();
    1829           0 :               aLoop != m_aDisabledControls.end();
    1830             :               ++aLoop
    1831             :             )
    1832             :         {
    1833           0 :             (*aLoop)->Enable( false );
    1834             :         }
    1835             :     }
    1836           0 : }
    1837             : 
    1838             : 
    1839           0 : void SvtFileDialog::EnableControl( Control* _pControl, bool _bEnable )
    1840             : {
    1841           0 :     if ( !_pControl )
    1842             :     {
    1843             :         SAL_WARN( "fpicker.office", "SvtFileDialog::EnableControl: invalid control!" );
    1844           0 :         return;
    1845             :     }
    1846             : 
    1847           0 :     _pControl->Enable( _bEnable );
    1848             : 
    1849           0 :     if ( _bEnable )
    1850             :     {
    1851           0 :         auto aPos = m_aDisabledControls.find( _pControl );
    1852           0 :         if ( m_aDisabledControls.end() != aPos )
    1853           0 :             m_aDisabledControls.erase( aPos );
    1854             :     }
    1855             :     else
    1856           0 :         m_aDisabledControls.insert( _pControl );
    1857             : }
    1858             : 
    1859             : 
    1860             : 
    1861           0 : short SvtFileDialog::PrepareExecute()
    1862             : {
    1863           0 :     OUString aEnvValue;
    1864           0 :     if ( getEnvironmentValue( "WorkDirMustContainRemovableMedia", aEnvValue ) && aEnvValue == "1" )
    1865             :     {
    1866             :         try
    1867             :         {
    1868           0 :             INetURLObject aStdDir( GetStandardDir() );
    1869             :             ::ucbhelper::Content aCnt( OUString( aStdDir.GetMainURL(
    1870             :                                                     INetURLObject::NO_DECODE ) ),
    1871             :                                  Reference< XCommandEnvironment >(),
    1872           0 :                                  comphelper::getProcessComponentContext() );
    1873           0 :             Sequence< OUString > aProps(2);
    1874           0 :             aProps[0] = "IsVolume";
    1875           0 :             aProps[1] = "IsRemoveable";
    1876             : 
    1877             :             Reference< XResultSet > xResultSet
    1878           0 :                 = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_ONLY );
    1879           0 :             if ( xResultSet.is() )
    1880             :             {
    1881           0 :                 Reference< XRow > xRow( xResultSet, UNO_QUERY );
    1882             : 
    1883           0 :                 bool bEmpty = true;
    1884           0 :                 if ( !xResultSet->next() )
    1885             :                 {
    1886             :                     // folder is empty
    1887           0 :                     bEmpty = true;
    1888             :                 }
    1889             :                 else
    1890             :                 {
    1891           0 :                                 bEmpty = false;
    1892             :                 }
    1893             : 
    1894           0 :                 if ( bEmpty )
    1895             :                 {
    1896           0 :                     ScopedVclPtrInstance< MessageDialog > aBox(this, SVT_RESSTR(STR_SVT_NOREMOVABLEDEVICE));
    1897           0 :                     aBox->Execute();
    1898           0 :                     return 0;
    1899           0 :                 }
    1900           0 :             }
    1901             :         }
    1902           0 :         catch ( ContentCreationException const & )
    1903             :         {
    1904             :         }
    1905           0 :         catch ( CommandAbortedException const & )
    1906             :         {
    1907             :         }
    1908             :     }
    1909             : 
    1910           0 :     if ( ( _pImp->_nStyle & WB_SAVEAS ) && m_bHasFilename )
    1911             :         // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
    1912             :         // - finally we're going to save that file, aren't we?
    1913           0 :         m_aContent.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST);
    1914             :     else
    1915           0 :         m_aContent.enableDefaultInteractionHandler();
    1916             : 
    1917             :     // possibly just a filename without a path
    1918           0 :     OUString aFileNameOnly;
    1919           0 :     if( !_aPath.isEmpty() && (_pImp->_eMode == FILEDLG_MODE_SAVE)
    1920           0 :                      && (_aPath.indexOf(':') == -1)
    1921           0 :                      && (_aPath.indexOf('\\') == -1)
    1922           0 :                      && (_aPath.indexOf('/') == -1))
    1923             :     {
    1924           0 :         aFileNameOnly = _aPath;
    1925           0 :         _aPath.clear();
    1926             :     }
    1927             : 
    1928             :     // no starting path specified?
    1929           0 :     if ( _aPath.isEmpty() )
    1930             :     {
    1931             :         // then use the standard directory
    1932           0 :         _aPath = lcl_ensureFinalSlash( _pImp->GetStandardDir() );
    1933             : 
    1934             :         // attach given filename to path
    1935           0 :         if ( !aFileNameOnly.isEmpty() )
    1936           0 :             _aPath += aFileNameOnly;
    1937             :     }
    1938             : 
    1939             : 
    1940           0 :     _aPath = implGetInitialURL( _aPath, GetStandardDir() );
    1941             : 
    1942           0 :     if ( _pImp->_nStyle & WB_SAVEAS && !m_bHasFilename )
    1943             :         // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
    1944             :         // - finally we're going to save that file, aren't we?
    1945           0 :         m_aContent.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST);
    1946             : 
    1947             :     // if applicable show filter
    1948           0 :     _pImp->InitFilterList();
    1949             : 
    1950             :     // set up initial filter
    1951           0 :     sal_uInt16 nFilterCount = GetFilterCount();
    1952           0 :     OUString aAll = SvtResId( STR_FILTERNAME_ALL ).toString();
    1953           0 :     bool bHasAll = _pImp->HasFilterListEntry( aAll );
    1954           0 :     if ( _pImp->GetCurFilter() || nFilterCount == 1 || ( nFilterCount == 2 && bHasAll ) )
    1955             :     {
    1956             :         // if applicable set the only filter or the only filter that
    1957             :         // does not refer to all files, as the current one
    1958           0 :         if ( !_pImp->GetCurFilter() )
    1959             :         {
    1960           0 :             sal_uInt16 nPos = 0;
    1961           0 :             if ( 2 == nFilterCount && bHasAll )
    1962             :             {
    1963           0 :                 nPos = nFilterCount;
    1964           0 :                 while ( nPos-- )
    1965             :                 {
    1966           0 :                     if ( aAll != GetFilterName( nPos ) )
    1967           0 :                         break;
    1968             :                 }
    1969             :             }
    1970           0 :             SvtFileDialogFilter_Impl* pNewCurFilter = &(*_pImp->_pFilter)[ nPos ];
    1971             :             DBG_ASSERT( pNewCurFilter, "SvtFileDialog::Execute: invalid filter pos!" );
    1972           0 :             _pImp->SetCurFilter( pNewCurFilter, pNewCurFilter->GetName() );
    1973             :         }
    1974             : 
    1975             :         // adjust view
    1976           0 :         _pImp->SelectFilterListEntry( _pImp->GetCurFilter()->GetName() );
    1977           0 :         SetDefaultExt( _pImp->GetCurFilter()->GetExtension() );
    1978           0 :         sal_Int32 nSepPos = GetDefaultExt().indexOf( FILEDIALOG_DEF_EXTSEP );
    1979           0 :         if ( nSepPos != -1 )
    1980           0 :             EraseDefaultExt( nSepPos );
    1981             :     }
    1982             :     else
    1983             :     {
    1984             :         // if applicable set respectively create filter for all files
    1985           0 :         if ( !bHasAll )
    1986             :         {
    1987           0 :             SvtFileDialogFilter_Impl* pAllFilter = implAddFilter( aAll, OUString(FILEDIALOG_FILTER_ALL) );
    1988           0 :             _pImp->InsertFilterListEntry( pAllFilter );
    1989           0 :             _pImp->SetCurFilter( pAllFilter, aAll );
    1990             :         }
    1991           0 :         _pImp->SelectFilterListEntry( aAll );
    1992             :     }
    1993             : 
    1994           0 :     _pImp->_pDefaultFilter = _pImp->GetCurFilter();
    1995             : 
    1996             :     // if applicable isolate filter
    1997           0 :     OUString aFilter;
    1998             : 
    1999           0 :     if ( !IsolateFilterFromPath_Impl( _aPath, aFilter ) )
    2000           0 :         return 0;
    2001             : 
    2002           0 :     sal_uInt16 nNewFilterFlags = adjustFilter( aFilter );
    2003           0 :     if ( nNewFilterFlags & ( FLT_NONEMPTY | FLT_USERFILTER ) )
    2004             :     {
    2005           0 :         _pImp->_pEdFileName->SetText( aFilter );
    2006             :     }
    2007             : 
    2008             :     // create and show instance for set path
    2009           0 :     INetURLObject aFolderURL( _aPath );
    2010           0 :     OUString aFileName( aFolderURL.getName( INetURLObject::LAST_SEGMENT, false ) );
    2011           0 :     sal_Int32 nFileNameLen = aFileName.getLength();
    2012           0 :     bool bFileToSelect = nFileNameLen != 0;
    2013           0 :     if ( bFileToSelect && aFileName[ nFileNameLen - 1 ] != '/' )
    2014             :     {
    2015           0 :         _pImp->_pEdFileName->SetText( GET_DECODED_NAME( aFolderURL ) );
    2016           0 :         aFolderURL.removeSegment();
    2017             :     }
    2018             : 
    2019           0 :     INetURLObject aObj = aFolderURL;
    2020           0 :     if ( aObj.GetProtocol() == INetProtocol::File )
    2021             :     {
    2022             :         // set folder as current directory
    2023           0 :         aObj.setFinalSlash();
    2024             :     }
    2025             : 
    2026           0 :     UpdateControls( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    2027             : 
    2028             :     // Somebody might want to enable some controls according to the current filter
    2029           0 :     FilterSelect();
    2030             : 
    2031           0 :     OpenURL_Impl( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    2032             : 
    2033           0 :     _pFileView->Show();
    2034           0 :     _pSplitter->Show();
    2035           0 :     SvtDefModalDialogParent_Impl aDefParent( this );
    2036             : 
    2037             :     // if applicable read and set size from ini
    2038           0 :     InitSize();
    2039             : 
    2040           0 :     return 1;
    2041             : }
    2042             : 
    2043             : 
    2044           0 : void SvtFileDialog::executeAsync( ::svt::AsyncPickerAction::Action _eAction,
    2045             :                                     const OUString& _rURL, const OUString& _rFilter )
    2046             : {
    2047             :     DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );
    2048             : 
    2049           0 :     m_pCurrentAsyncAction = new AsyncPickerAction( this, _pFileView, _eAction );
    2050             : 
    2051           0 :     bool bReallyAsync = true;
    2052           0 :     m_aConfiguration.getNodeValue( OUString( "FillAsynchronously" ) ) >>= bReallyAsync;
    2053             : 
    2054           0 :     sal_Int32 nMinTimeout = 0;
    2055           0 :     m_aConfiguration.getNodeValue( OUString( "Timeout/Min" ) ) >>= nMinTimeout;
    2056           0 :     sal_Int32 nMaxTimeout = 0;
    2057           0 :     m_aConfiguration.getNodeValue( OUString( "Timeout/Max" ) ) >>= nMaxTimeout;
    2058             : 
    2059           0 :     m_bInExecuteAsync = true;
    2060           0 :     m_pCurrentAsyncAction->execute( _rURL, _rFilter, bReallyAsync ? nMinTimeout : -1, nMaxTimeout, GetBlackList() );
    2061           0 :     m_bInExecuteAsync = false;
    2062           0 : }
    2063             : 
    2064             : 
    2065             : 
    2066           0 : void SvtFileDialog::FileSelect()
    2067             : {
    2068           0 :     if ( _pFileNotifier )
    2069           0 :         _pFileNotifier->notify( FILE_SELECTION_CHANGED, 0 );
    2070           0 : }
    2071             : 
    2072             : 
    2073             : 
    2074           0 : void SvtFileDialog::FilterSelect()
    2075             : {
    2076           0 :     if ( _pFileNotifier )
    2077             :         _pFileNotifier->notify( CTRL_STATE_CHANGED,
    2078           0 :                                 LISTBOX_FILTER );
    2079           0 : }
    2080             : 
    2081             : 
    2082             : 
    2083           0 : void SvtFileDialog::SetStandardDir( const OUString& rStdDir )
    2084             : 
    2085             : /*  [Description]
    2086             : 
    2087             :    This method sets the path for the default button.
    2088             : */
    2089             : 
    2090             : {
    2091           0 :     INetURLObject aObj( rStdDir );
    2092             :     DBG_ASSERT( aObj.GetProtocol() != INetProtocol::NotValid, "Invalid protocol!" );
    2093           0 :     aObj.setFinalSlash();
    2094           0 :     _pImp->SetStandardDir( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    2095           0 : }
    2096             : 
    2097           0 : void SvtFileDialog::SetBlackList( const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
    2098             : {
    2099           0 :     _pImp->SetBlackList( rBlackList );
    2100           0 : }
    2101             : 
    2102             : 
    2103             : 
    2104           0 : const ::com::sun::star::uno::Sequence< OUString >& SvtFileDialog::GetBlackList() const
    2105             : {
    2106           0 :     return _pImp->GetBlackList();
    2107             : }
    2108             : 
    2109             : 
    2110           0 : const OUString& SvtFileDialog::GetStandardDir() const
    2111             : 
    2112             : /*  [Description]
    2113             : 
    2114             :     This method returns the standard path.
    2115             : */
    2116             : 
    2117             : {
    2118           0 :     return _pImp->GetStandardDir();
    2119             : }
    2120             : 
    2121             : 
    2122             : 
    2123           0 : void SvtFileDialog::PrevLevel_Impl()
    2124             : {
    2125           0 :     _pFileView->EndInplaceEditing( false );
    2126             : 
    2127           0 :     OUString sDummy;
    2128           0 :     executeAsync( AsyncPickerAction::ePrevLevel, sDummy, sDummy );
    2129           0 : }
    2130             : 
    2131             : 
    2132             : 
    2133           0 : void SvtFileDialog::OpenURL_Impl( const OUString& _rURL )
    2134             : {
    2135           0 :     _pFileView->EndInplaceEditing( false );
    2136             : 
    2137           0 :     executeAsync( AsyncPickerAction::eOpenURL, _rURL, getMostCurrentFilter( _pImp ) );
    2138           0 : }
    2139             : 
    2140             : 
    2141           0 : SvtFileDialogFilter_Impl* SvtFileDialog::implAddFilter( const OUString& _rFilter, const OUString& _rType )
    2142             : {
    2143           0 :     SvtFileDialogFilter_Impl* pNewFilter = new SvtFileDialogFilter_Impl( _rFilter, _rType );
    2144           0 :     _pImp->_pFilter->push_front( pNewFilter );
    2145             : 
    2146           0 :     if ( !_pImp->GetCurFilter() )
    2147           0 :         _pImp->SetCurFilter( pNewFilter, _rFilter );
    2148             : 
    2149           0 :     return pNewFilter;
    2150             : }
    2151             : 
    2152             : 
    2153             : 
    2154           0 : void SvtFileDialog::AddFilter( const OUString& _rFilter, const OUString& _rType )
    2155             : {
    2156             :     DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
    2157           0 :     implAddFilter ( _rFilter, _rType );
    2158           0 : }
    2159             : 
    2160             : 
    2161           0 : void SvtFileDialog::AddFilterGroup( const OUString& _rFilter, const Sequence< StringPair >& _rFilters )
    2162             : {
    2163             :     DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
    2164             : 
    2165           0 :     implAddFilter( _rFilter, OUString() );
    2166           0 :     const StringPair* pSubFilters       =               _rFilters.getConstArray();
    2167           0 :     const StringPair* pSubFiltersEnd    = pSubFilters + _rFilters.getLength();
    2168           0 :     for ( ; pSubFilters != pSubFiltersEnd; ++pSubFilters )
    2169           0 :         implAddFilter( pSubFilters->First, pSubFilters->Second );
    2170           0 : }
    2171             : 
    2172             : 
    2173           0 : void SvtFileDialog::SetCurFilter( const OUString& rFilter )
    2174             : {
    2175             :     DBG_ASSERT( !IsInExecute(), "SvtFileDialog::SetCurFilter: currently executing!" );
    2176             : 
    2177             :     // look for corresponding filter
    2178           0 :     sal_uInt16 nPos = _pImp->_pFilter->size();
    2179             : 
    2180           0 :     while ( nPos-- )
    2181             :     {
    2182           0 :         SvtFileDialogFilter_Impl* pFilter = &(*_pImp->_pFilter)[ nPos ];
    2183           0 :         if ( pFilter->GetName() == rFilter )
    2184             :         {
    2185           0 :             _pImp->SetCurFilter( pFilter, rFilter );
    2186           0 :             break;
    2187             :         }
    2188             :     }
    2189           0 : }
    2190             : 
    2191             : 
    2192             : 
    2193           0 : OUString SvtFileDialog::GetCurFilter() const
    2194             : {
    2195           0 :     OUString aFilter;
    2196             : 
    2197           0 :     const SvtFileDialogFilter_Impl* pCurrentFilter = _pImp->GetCurFilter();
    2198           0 :     if ( pCurrentFilter )
    2199           0 :         aFilter = pCurrentFilter->GetName();
    2200             : 
    2201           0 :     return aFilter;
    2202             : }
    2203             : 
    2204           0 : OUString SvtFileDialog::getCurFilter( ) const
    2205             : {
    2206           0 :     return GetCurFilter();
    2207             : }
    2208             : 
    2209             : 
    2210             : 
    2211           0 : sal_uInt16 SvtFileDialog::GetFilterCount() const
    2212             : {
    2213           0 :     return _pImp->_pFilter->size();
    2214             : }
    2215             : 
    2216             : 
    2217             : 
    2218           0 : const OUString& SvtFileDialog::GetFilterName( sal_uInt16 nPos ) const
    2219             : {
    2220             :     DBG_ASSERT( nPos < GetFilterCount(), "invalid index" );
    2221           0 :     return (*_pImp->_pFilter)[ nPos ].GetName();
    2222             : }
    2223             : 
    2224             : 
    2225             : 
    2226           0 : void SvtFileDialog::InitSize()
    2227             : {
    2228           0 :     if ( _pImp->_aIniKey.isEmpty() )
    2229           0 :         return;
    2230             : 
    2231             :     // initialize from config
    2232           0 :     SvtViewOptions aDlgOpt( E_DIALOG, _pImp->_aIniKey );
    2233             : 
    2234           0 :     if ( aDlgOpt.Exists() )
    2235             :     {
    2236           0 :         SetWindowState(OUStringToOString(aDlgOpt.GetWindowState(), osl_getThreadTextEncoding()));
    2237             : 
    2238           0 :         Any aUserData = aDlgOpt.GetUserItem( OUString( "UserData" ));
    2239           0 :         OUString sCfgStr;
    2240           0 :         if ( aUserData >>= sCfgStr )
    2241           0 :             _pFileView->SetConfigString( sCfgStr );
    2242           0 :     }
    2243             : }
    2244             : 
    2245             : 
    2246             : 
    2247           0 : std::vector<OUString> SvtFileDialog::GetPathList() const
    2248             : {
    2249           0 :     std::vector<OUString> aList;
    2250           0 :     sal_uLong           nCount = _pFileView->GetSelectionCount();
    2251           0 :     SvTreeListEntry*    pEntry = nCount ? _pFileView->FirstSelected() : NULL;
    2252             : 
    2253           0 :     if ( ! pEntry )
    2254             :     {
    2255           0 :         if ( !_pImp->_pEdFileName->GetText().isEmpty() && _bIsInExecute )
    2256           0 :             aList.push_back(_pImp->_pEdFileName->GetURL());
    2257             :         else
    2258           0 :             aList.push_back(_aPath);
    2259             :     }
    2260             :     else
    2261             :     {
    2262           0 :         while ( pEntry )
    2263             :         {
    2264           0 :             aList.push_back(SvtFileView::GetURL(pEntry));
    2265           0 :             pEntry = _pFileView->NextSelected( pEntry );
    2266             :         }
    2267             :     }
    2268             : 
    2269           0 :     return aList;
    2270             : }
    2271             : 
    2272             : 
    2273           0 : bool SvtFileDialog::IsolateFilterFromPath_Impl( OUString& rPath, OUString& rFilter )
    2274             : {
    2275           0 :     OUString aEmpty;
    2276           0 :     OUString aReversePath = comphelper::string::reverseString(rPath);
    2277           0 :     sal_Int32 nQuestionMarkPos = rPath.indexOf( '?' );
    2278           0 :     sal_Int32 nWildCardPos = rPath.indexOf( FILEDIALOG_DEF_WILDCARD );
    2279             : 
    2280           0 :     if ( nQuestionMarkPos != -1 )
    2281             :     {
    2282             :         // use question mark as wildcard only for files
    2283           0 :         INetProtocol eProt = INetURLObject::CompareProtocolScheme( rPath );
    2284             : 
    2285           0 :         if ( INetProtocol::NotValid != eProt && INetProtocol::File != eProt )
    2286           0 :             nQuestionMarkPos = -1;
    2287             : 
    2288           0 :         nWildCardPos = std::min( nWildCardPos, nQuestionMarkPos );
    2289             :     }
    2290             : 
    2291           0 :     rFilter = aEmpty;
    2292             : 
    2293           0 :     if ( nWildCardPos != -1 )
    2294             :     {
    2295           0 :         sal_Int32 nPathTokenPos = aReversePath.indexOf( '/' );
    2296             : 
    2297           0 :         if ( nPathTokenPos == -1 )
    2298             :         {
    2299             :             OUString aDelim(
    2300             : #if defined(WNT)
    2301             :                     '\\'
    2302             : #else
    2303             :                     '/'
    2304             : #endif
    2305           0 :             );
    2306             : 
    2307           0 :             nPathTokenPos = aReversePath.indexOf( aDelim );
    2308             : #if !defined( UNX )
    2309             :             if ( nPathTokenPos == -1 )
    2310             :             {
    2311             :                 nPathTokenPos = aReversePath.indexOf( ':' );
    2312             :             }
    2313             : #endif
    2314             :         }
    2315             : 
    2316             :         // check syntax
    2317           0 :         if ( nPathTokenPos != -1 )
    2318             :         {
    2319           0 :             if ( nPathTokenPos < (rPath.getLength() - nWildCardPos - 1) )
    2320             :             {
    2321           0 :                 ErrorHandler::HandleError( ERRCODE_SFX_INVALIDSYNTAX );
    2322           0 :                 return false;
    2323             :             }
    2324             : 
    2325             :             // cut off filter
    2326           0 :             rFilter = aReversePath;
    2327           0 :             rFilter = rFilter.copy( 0, nPathTokenPos );
    2328           0 :             rFilter = comphelper::string::reverseString(rFilter);
    2329             : 
    2330             :             // determine folder
    2331           0 :             rPath = aReversePath;
    2332           0 :             rPath = rPath.copy( nPathTokenPos );
    2333           0 :             rPath = comphelper::string::reverseString(rPath);
    2334             :         }
    2335             :         else
    2336             :         {
    2337           0 :             rFilter = rPath;
    2338           0 :             rPath = aEmpty;
    2339             :         }
    2340             :     }
    2341             : 
    2342           0 :     return true;
    2343             : }
    2344             : 
    2345             : 
    2346           0 : void SvtFileDialog::implUpdateImages( )
    2347             : {
    2348           0 :     m_aImages = ImageList( SvtResId( RID_FILEPICKER_IMAGES ) );
    2349             : 
    2350             :     // set the appropriate images on the buttons
    2351           0 :     if ( _pImp->_pBtnUp )
    2352           0 :         _pImp->_pBtnUp->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_UP ) );
    2353             : 
    2354           0 :     if ( _pImp->_pBtnNewFolder )
    2355           0 :         _pImp->_pBtnNewFolder->SetModeImage( GetButtonImage( IMG_FILEDLG_CREATEFOLDER ) );
    2356           0 : }
    2357             : 
    2358             : 
    2359           0 : void SvtFileDialog::DataChanged( const DataChangedEvent& _rDCEvt )
    2360             : {
    2361           0 :     if ( DataChangedEventType::SETTINGS == _rDCEvt.GetType() )
    2362           0 :         implUpdateImages( );
    2363             : 
    2364           0 :     ModalDialog::DataChanged( _rDCEvt );
    2365           0 : }
    2366             : 
    2367             : 
    2368           0 : void SvtFileDialog::Resize()
    2369             : {
    2370           0 :     Dialog::Resize();
    2371             : 
    2372           0 :     if ( IsRollUp() )
    2373           0 :         return;
    2374             : 
    2375           0 :     if ( _pFileNotifier )
    2376           0 :         _pFileNotifier->notify( DIALOG_SIZE_CHANGED, 0 );
    2377             : }
    2378             : 
    2379           0 : Control* SvtFileDialog::getControl( sal_Int16 _nControlId, bool _bLabelControl ) const
    2380             : {
    2381           0 :     Control* pReturn = NULL;
    2382             : 
    2383           0 :     switch ( _nControlId )
    2384             :     {
    2385             :         case CONTROL_FILEVIEW:
    2386           0 :             pReturn = _bLabelControl ? NULL : static_cast< Control* >( _pFileView );
    2387           0 :             break;
    2388             : 
    2389             :         case EDIT_FILEURL:
    2390             :             pReturn =   _bLabelControl
    2391           0 :                     ?   static_cast< Control* >( _pImp->_pFtFileName )
    2392           0 :                     :   static_cast< Control* >( _pImp->_pEdFileName );
    2393           0 :             break;
    2394             : 
    2395             :         case EDIT_FILEURL_LABEL:
    2396           0 :             pReturn = static_cast< Control* >( _pImp->_pFtFileName );
    2397           0 :             break;
    2398             : 
    2399             :         case CHECKBOX_AUTOEXTENSION:
    2400           0 :             pReturn = _pImp->_pCbAutoExtension;
    2401           0 :             break;
    2402             : 
    2403             :         case CHECKBOX_PASSWORD:
    2404           0 :             pReturn = _pImp->_pCbPassword;
    2405           0 :             break;
    2406             : 
    2407             :         case CHECKBOX_FILTEROPTIONS:
    2408           0 :             pReturn = _pImp->_pCbOptions;
    2409           0 :             break;
    2410             : 
    2411             :         case CHECKBOX_READONLY:
    2412           0 :             pReturn = _pCbReadOnly;
    2413           0 :             break;
    2414             : 
    2415             :         case CHECKBOX_LINK:
    2416           0 :             pReturn = _pCbLinkBox;
    2417           0 :             break;
    2418             : 
    2419             :         case CHECKBOX_PREVIEW:
    2420           0 :             pReturn = _pCbPreviewBox;
    2421           0 :             break;
    2422             : 
    2423             :         case CHECKBOX_SELECTION:
    2424           0 :             pReturn = _pCbSelection;
    2425           0 :             break;
    2426             : 
    2427             :         case LISTBOX_FILTER:
    2428           0 :             pReturn = _bLabelControl ? _pImp->_pFtFileType : _pImp->GetFilterListControl();
    2429           0 :             break;
    2430             : 
    2431             :         case LISTBOX_FILTER_LABEL:
    2432           0 :             pReturn = _pImp->_pFtFileType;
    2433           0 :             break;
    2434             : 
    2435             :         case FIXEDTEXT_CURRENTFOLDER:
    2436           0 :             pReturn = _pImp->_pEdCurrentPath;
    2437           0 :             break;
    2438             : 
    2439             :         case LISTBOX_VERSION:
    2440             :             pReturn =   _bLabelControl
    2441           0 :                     ?   static_cast< Control* >( _pImp->_pFtFileVersion )
    2442           0 :                     :   static_cast< Control* >( _pImp->_pLbFileVersion );
    2443           0 :             break;
    2444             : 
    2445             :         case LISTBOX_TEMPLATE:
    2446             :             pReturn =   _bLabelControl
    2447           0 :                     ?   static_cast< Control* >( _pImp->_pFtTemplates )
    2448           0 :                     :   static_cast< Control* >( _pImp->_pLbTemplates );
    2449           0 :             break;
    2450             : 
    2451             :         case LISTBOX_IMAGE_TEMPLATE:
    2452             :             pReturn =   _bLabelControl
    2453           0 :                     ?   static_cast< Control* >( _pImp->_pFtImageTemplates )
    2454           0 :                     :   static_cast< Control* >( _pImp->_pLbImageTemplates );
    2455           0 :             break;
    2456             : 
    2457             :         case LISTBOX_VERSION_LABEL:
    2458           0 :             pReturn = _pImp->_pFtFileVersion;
    2459           0 :             break;
    2460             : 
    2461             :         case LISTBOX_TEMPLATE_LABEL:
    2462           0 :             pReturn = _pImp->_pFtTemplates;
    2463           0 :             break;
    2464             : 
    2465             :         case LISTBOX_IMAGE_TEMPLATE_LABEL:
    2466           0 :             pReturn = _pImp->_pFtImageTemplates;
    2467           0 :             break;
    2468             : 
    2469             :         case PUSHBUTTON_OK:
    2470           0 :             pReturn = _pImp->_pBtnFileOpen;
    2471           0 :             break;
    2472             : 
    2473             :         case PUSHBUTTON_CANCEL:
    2474           0 :             pReturn = _pImp->_pBtnCancel;
    2475           0 :             break;
    2476             : 
    2477             :         case PUSHBUTTON_PLAY:
    2478           0 :             pReturn = _pPbPlay;
    2479           0 :             break;
    2480             : 
    2481             :         case PUSHBUTTON_HELP:
    2482           0 :             pReturn = _pImp->_pBtnHelp;
    2483           0 :             break;
    2484             : 
    2485             :         case TOOLBOXBUTOON_LEVEL_UP:
    2486           0 :             pReturn = _pImp->_pBtnUp;
    2487           0 :             break;
    2488             : 
    2489             :         case TOOLBOXBUTOON_NEW_FOLDER:
    2490           0 :             pReturn = _pImp->_pBtnNewFolder;
    2491           0 :             break;
    2492             : 
    2493             :         case LISTBOX_FILTER_SELECTOR:
    2494             :             // only exists on SalGtkFilePicker
    2495           0 :             break;
    2496             : 
    2497             :         default:
    2498             :             SAL_WARN( "fpicker.office", "SvtFileDialog::getControl: invalid id!" );
    2499             :     }
    2500           0 :     return pReturn;
    2501             : }
    2502             : 
    2503             : 
    2504           0 : void SvtFileDialog::enableControl( sal_Int16 _nControlId, bool _bEnable )
    2505             : {
    2506           0 :     Control* pControl = getControl( _nControlId, false );
    2507           0 :     if ( pControl )
    2508           0 :         EnableControl( pControl, _bEnable );
    2509           0 :     Control* pLabel = getControl( _nControlId, true );
    2510           0 :     if ( pLabel )
    2511           0 :         EnableControl( pLabel, _bEnable );
    2512           0 : }
    2513             : 
    2514             : 
    2515           0 : void SvtFileDialog::AddControls_Impl( )
    2516             : {
    2517             :     // create the "insert as link" checkbox, if needed
    2518           0 :     if ( _nExtraBits & SFX_EXTRA_INSERTASLINK )
    2519             :     {
    2520           0 :         _pCbLinkBox ->SetText( SvtResId( STR_SVT_FILEPICKER_INSERT_AS_LINK ) );
    2521           0 :         _pCbLinkBox ->SetHelpId( HID_FILEDLG_LINK_CB );
    2522           0 :         _pCbLinkBox->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
    2523           0 :         _pCbLinkBox->Show();
    2524             :     }
    2525             : 
    2526             :     // create the "show preview" checkbox ( and the preview window, too ), if needed
    2527           0 :     if ( _nExtraBits & SFX_EXTRA_SHOWPREVIEW  )
    2528             :     {
    2529           0 :         _pImp->_aIniKey = "ImportGraphicDialog";
    2530             :         // because the "<All Formats> (*.bmp,*...)" entry is to wide,
    2531             :         // we need to disable the auto width feature of the filter box
    2532           0 :         _pImp->DisableFilterBoxAutoWidth();
    2533             : 
    2534             :         // "preview"
    2535           0 :         _pCbPreviewBox->SetText( SvtResId( STR_SVT_FILEPICKER_SHOW_PREVIEW ) );
    2536           0 :         _pCbPreviewBox->SetHelpId( HID_FILEDLG_PREVIEW_CB );
    2537           0 :         _pCbPreviewBox->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
    2538           0 :         _pCbPreviewBox->Show();
    2539             : 
    2540             :         // generate preview window just here
    2541           0 :         _pPrevWin->SetOutputSizePixel(Size(200, 300));
    2542           0 :         _pPrevWin->Show();
    2543             : 
    2544           0 :         _pPrevBmp = VclPtr<FixedBitmap>::Create( _pPrevWin, WinBits( WB_BORDER ) );
    2545           0 :         _pPrevBmp->SetBackground( Wallpaper( Color( COL_WHITE ) ) );
    2546           0 :         _pPrevBmp->SetSizePixel(_pPrevWin->GetSizePixel());
    2547           0 :         _pPrevBmp->Show();
    2548           0 :         _pPrevBmp->SetAccessibleName(SVT_RESSTR(STR_PREVIEW));
    2549             :     }
    2550             : 
    2551           0 :     if ( _nExtraBits & SFX_EXTRA_AUTOEXTENSION )
    2552             :     {
    2553           0 :         _pImp->_pCbAutoExtension->SetText( SvtResId( STR_SVT_FILEPICKER_AUTO_EXTENSION ) );
    2554           0 :         _pImp->_pCbAutoExtension->Check( true );
    2555           0 :         _pImp->_pCbAutoExtension->SetClickHdl( LINK( this, SvtFileDialog, AutoExtensionHdl_Impl ) );
    2556           0 :         _pImp->_pCbAutoExtension->Show();
    2557             :     }
    2558             : 
    2559           0 :     if ( _nExtraBits & SFX_EXTRA_FILTEROPTIONS )
    2560             :     {
    2561           0 :         _pImp->_pCbOptions->SetText( SvtResId( STR_SVT_FILEPICKER_FILTER_OPTIONS ) );
    2562           0 :         _pImp->_pCbOptions->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
    2563           0 :         _pImp->_pCbOptions->Show();
    2564             :     }
    2565             : 
    2566           0 :     if ( _nExtraBits & SFX_EXTRA_SELECTION )
    2567             :     {
    2568           0 :         _pCbSelection->SetText( SvtResId( STR_SVT_FILEPICKER_SELECTION ) );
    2569           0 :         _pCbSelection->SetClickHdl( LINK( this, SvtFileDialog, ClickHdl_Impl ) );
    2570           0 :         _pCbSelection->Show();
    2571             :     }
    2572             : 
    2573           0 :     if ( _nExtraBits & SFX_EXTRA_PLAYBUTTON )
    2574             :     {
    2575           0 :         _pPbPlay->SetText( SvtResId( STR_SVT_FILEPICKER_PLAY ) );
    2576           0 :         _pPbPlay->SetHelpId( HID_FILESAVE_DOPLAY );
    2577           0 :         _pPbPlay->SetClickHdl( LINK( this, SvtFileDialog, PlayButtonHdl_Impl ) );
    2578           0 :         _pPbPlay->Show();
    2579             :     }
    2580             : 
    2581           0 :     if ( _nExtraBits & SFX_EXTRA_SHOWVERSIONS )
    2582             :     {
    2583           0 :         _pImp->_pFtFileVersion->SetText( SvtResId( STR_SVT_FILEPICKER_VERSION ) );
    2584           0 :         _pImp->_pFtFileVersion->Show();
    2585             : 
    2586           0 :         _pImp->_pLbFileVersion->SetHelpId( HID_FILEOPEN_VERSION );
    2587           0 :         _pImp->_pLbFileVersion->Show();
    2588             :     }
    2589           0 :     else if ( _nExtraBits & SFX_EXTRA_TEMPLATES )
    2590             :     {
    2591           0 :         _pImp->_pFtTemplates->SetText( SvtResId( STR_SVT_FILEPICKER_TEMPLATES ) );
    2592           0 :         _pImp->_pFtTemplates->Show();
    2593             : 
    2594           0 :         _pImp->_pLbTemplates->SetHelpId( HID_FILEOPEN_VERSION );
    2595           0 :         _pImp->_pLbTemplates->Show();
    2596             :             // This is strange. During the re-factoring during 96930, I discovered that this help id
    2597             :             // is set in the "Templates mode". This was hidden in the previous implementation.
    2598             :             // Shouldn't this be a more meaningfull help id.
    2599             :     }
    2600           0 :     else if ( _nExtraBits & SFX_EXTRA_IMAGE_TEMPLATE )
    2601             :     {
    2602           0 :         _pImp->_pFtImageTemplates->SetText( SvtResId( STR_SVT_FILEPICKER_IMAGE_TEMPLATE ) );
    2603           0 :         _pImp->_pFtImageTemplates->Show();
    2604             : 
    2605           0 :         _pImp->_pLbImageTemplates->SetHelpId( HID_FILEOPEN_IMAGE_TEMPLATE );
    2606           0 :         _pImp->_pLbImageTemplates->Show();
    2607             :     }
    2608             : 
    2609           0 :     _pImp->_pPlaces = VclPtr<PlacesListBox>::Create(_pContainer, this, SVT_RESSTR(STR_PLACES_TITLE), WB_BORDER);
    2610           0 :     _pImp->_pPlaces->SetHelpId("SVT_HID_FILESAVE_PLACES_LISTBOX");
    2611           0 :     Size aSize(LogicToPixel(Size(50, 85), MAP_APPFONT));
    2612           0 :     _pImp->_pPlaces->set_height_request(aSize.Height());
    2613           0 :     _pImp->_pPlaces->set_width_request(aSize.Width());
    2614           0 :     _pImp->_pPlaces->SetSizePixel(aSize);
    2615           0 :     _pImp->_pPlaces->Show();
    2616             : 
    2617           0 :     sal_Int32 nPosX = _pImp->_pPlaces->GetSizePixel().Width();
    2618           0 :     _pSplitter->SetPosPixel(Point(nPosX, 0));
    2619           0 :     nPosX += _pSplitter->GetSizePixel().Width();
    2620           0 :     _pFileView->SetPosPixel(Point(nPosX, 0));
    2621             : 
    2622           0 :     _pImp->_pPlaces->SetAddHdl( LINK ( this, SvtFileDialog, AddPlacePressed_Hdl ) );
    2623           0 :     _pImp->_pPlaces->SetDelHdl( LINK ( this, SvtFileDialog, RemovePlacePressed_Hdl ) );
    2624             : 
    2625           0 :     initDefaultPlaces();
    2626           0 : }
    2627             : 
    2628             : 
    2629           0 : sal_Int32 SvtFileDialog::getTargetColorDepth()
    2630             : {
    2631           0 :     if ( _pPrevBmp )
    2632           0 :         return _pPrevBmp->GetBitCount();
    2633             :     else
    2634           0 :         return 0;
    2635             : }
    2636             : 
    2637             : 
    2638           0 : sal_Int32 SvtFileDialog::getAvailableWidth()
    2639             : {
    2640           0 :     if ( _pPrevBmp )
    2641           0 :         return _pPrevBmp->GetOutputSizePixel().Width();
    2642             :     else
    2643           0 :         return 0;
    2644             : }
    2645             : 
    2646             : 
    2647           0 : sal_Int32 SvtFileDialog::getAvailableHeight()
    2648             : {
    2649           0 :     if ( _pPrevBmp )
    2650           0 :         return _pPrevBmp->GetOutputSizePixel().Height();
    2651             :     else
    2652           0 :         return 0;
    2653             : }
    2654             : 
    2655             : 
    2656           0 : void SvtFileDialog::setImage( sal_Int16 /*aImageFormat*/, const Any& rImage )
    2657             : {
    2658           0 :     if ( ! _pPrevBmp || ! _pPrevBmp->IsVisible() )
    2659           0 :         return;
    2660             : 
    2661           0 :     Sequence < sal_Int8 > aBmpSequence;
    2662             : 
    2663           0 :     if ( rImage >>= aBmpSequence )
    2664             :     {
    2665           0 :         Bitmap          aBmp;
    2666           0 :         SvMemoryStream  aData( aBmpSequence.getArray(),
    2667           0 :                                aBmpSequence.getLength(),
    2668           0 :                                StreamMode::READ );
    2669           0 :         ReadDIB(aBmp, aData, true);
    2670             : 
    2671           0 :         _pPrevBmp->SetBitmap( aBmp );
    2672             :     }
    2673             :     else
    2674             :     {
    2675           0 :         Bitmap aEmpty;
    2676           0 :         _pPrevBmp->SetBitmap( aEmpty );
    2677           0 :     }
    2678             : }
    2679             : 
    2680             : 
    2681           0 : OUString SvtFileDialog::getCurrentFileText( ) const
    2682             : {
    2683           0 :     OUString sReturn;
    2684           0 :     if ( _pImp && _pImp->_pEdFileName )
    2685           0 :         sReturn = _pImp->_pEdFileName->GetText();
    2686           0 :     return sReturn;
    2687             : }
    2688             : 
    2689             : 
    2690           0 : void SvtFileDialog::setCurrentFileText( const OUString& _rText, bool _bSelectAll )
    2691             : {
    2692           0 :     if ( _pImp && _pImp->_pEdFileName )
    2693             :     {
    2694           0 :         _pImp->_pEdFileName->SetText( _rText );
    2695           0 :         if ( _bSelectAll )
    2696           0 :             _pImp->_pEdFileName->SetSelection( Selection( 0, _rText.getLength() ) );
    2697             :     }
    2698           0 : }
    2699             : 
    2700             : 
    2701           0 : bool SvtFileDialog::isAutoExtensionEnabled()
    2702             : {
    2703           0 :     return _pImp->_pCbAutoExtension && _pImp->_pCbAutoExtension->IsChecked();
    2704             : }
    2705             : 
    2706             : 
    2707           0 : bool SvtFileDialog::getShowState()
    2708             : {
    2709           0 :     if ( _pPrevBmp )
    2710           0 :         return _pPrevBmp->IsVisible();
    2711             :     else
    2712           0 :         return false;
    2713             : }
    2714             : 
    2715           0 : bool SvtFileDialog::ContentHasParentFolder( const OUString& rURL )
    2716             : {
    2717           0 :     m_aContent.bindTo( rURL );
    2718             : 
    2719           0 :     if ( m_aContent.isInvalid() )
    2720           0 :         return false;
    2721             : 
    2722           0 :     return m_aContent.hasParentFolder( ) && m_aContent.isValid();
    2723             : }
    2724             : 
    2725           0 : bool SvtFileDialog::ContentCanMakeFolder( const OUString& rURL )
    2726             : {
    2727           0 :     m_aContent.bindTo( rURL );
    2728             : 
    2729           0 :     if ( m_aContent.isInvalid() )
    2730           0 :         return false;
    2731             : 
    2732           0 :     return m_aContent.canCreateFolder( ) && m_aContent.isValid();
    2733             : }
    2734             : 
    2735           0 : bool SvtFileDialog::ContentGetTitle( const OUString& rURL, OUString& rTitle )
    2736             : {
    2737           0 :     m_aContent.bindTo( rURL );
    2738             : 
    2739           0 :     if ( m_aContent.isInvalid() )
    2740           0 :         return false;
    2741             : 
    2742           0 :     OUString sTitle;
    2743           0 :     m_aContent.getTitle( sTitle );
    2744           0 :     rTitle = sTitle;
    2745             : 
    2746           0 :     return m_aContent.isValid();
    2747             : }
    2748             : 
    2749           0 : void SvtFileDialog::appendDefaultExtension(OUString& _rFileName,
    2750             :                                            const OUString& _rFilterDefaultExtension,
    2751             :                                            const OUString& _rFilterExtensions)
    2752             : {
    2753           0 :     OUString aTemp(_rFileName);
    2754           0 :     aTemp = aTemp.toAsciiLowerCase();
    2755           0 :     OUString aType(_rFilterExtensions);
    2756           0 :     aType = aType.toAsciiLowerCase();
    2757             : 
    2758           0 :     if ( aType != FILEDIALOG_FILTER_ALL )
    2759             :     {
    2760           0 :         sal_uInt16 nWildCard = comphelper::string::getTokenCount(aType, FILEDIALOG_DEF_EXTSEP);
    2761             :         sal_uInt16 nIndex;
    2762           0 :         sal_Int32 nPos = 0;
    2763             : 
    2764           0 :         for ( nIndex = 0; nIndex < nWildCard; nIndex++ )
    2765             :         {
    2766           0 :             OUString aExt(aType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nPos ));
    2767             :             // take care of a leading *
    2768           0 :             sal_Int32 nExtOffset = (aExt[0] == '*' ? 1 : 0);
    2769           0 :             const sal_Unicode* pExt = aExt.getStr() + nExtOffset;
    2770           0 :             sal_Int32 nExtLen = aExt.getLength() - nExtOffset;
    2771           0 :             sal_Int32 nOffset = aTemp.getLength() - nExtLen;
    2772             :             // minimize search by starting at last possible index
    2773           0 :             if ( aTemp.indexOf(pExt, nOffset) == nOffset )
    2774           0 :                 break;
    2775           0 :         }
    2776             : 
    2777           0 :         if ( nIndex >= nWildCard )
    2778             :         {
    2779           0 :             _rFileName += ".";
    2780           0 :             _rFileName += _rFilterDefaultExtension;
    2781             :         }
    2782           0 :     }
    2783           0 : }
    2784             : 
    2785           0 : void SvtFileDialog::initDefaultPlaces( )
    2786             : {
    2787           0 :     PlacePtr pRootPlace( new Place( SVT_RESSTR(STR_DEFAULT_DIRECTORY), GetStandardDir() ) );
    2788           0 :     _pImp->_pPlaces->AppendPlace( pRootPlace );
    2789             : 
    2790             :     // Load from user settings
    2791           0 :     Sequence< OUString > placesUrlsList(officecfg::Office::Common::Misc::FilePickerPlacesUrls::get(m_context));
    2792           0 :     Sequence< OUString > placesNamesList(officecfg::Office::Common::Misc::FilePickerPlacesNames::get(m_context));
    2793             : 
    2794           0 :     for(sal_Int32 nPlace = 0; nPlace < placesUrlsList.getLength() && nPlace < placesNamesList.getLength(); ++nPlace)
    2795             :     {
    2796           0 :         PlacePtr pPlace(new Place(placesNamesList[nPlace], placesUrlsList[nPlace], true));
    2797           0 :         _pImp->_pPlaces->AppendPlace(pPlace);
    2798           0 :     }
    2799             : 
    2800             :     // Reset the placesList "updated" state
    2801           0 :     _pImp->_pPlaces->IsUpdated();
    2802           0 : }
    2803             : 
    2804           0 : IMPL_LINK_NOARG( SvtFileDialog, Split_Hdl )
    2805             : {
    2806           0 :     sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
    2807             : 
    2808             :     // Resize the places list
    2809           0 :     sal_Int32 nPlaceX = _pImp->_pPlaces->GetPosPixel( ).X();
    2810           0 :     Size placeSize = _pImp->_pPlaces->GetSizePixel( );
    2811           0 :     placeSize.Width() = nSplitPos - nPlaceX;
    2812           0 :     _pImp->_pPlaces->SetSizePixel( placeSize );
    2813             : 
    2814             :     // Change Pos and size of the fileview
    2815           0 :     Point fileViewPos = _pFileView->GetPosPixel();
    2816           0 :     sal_Int32 nOldX = fileViewPos.X();
    2817           0 :     sal_Int32 nNewX = nSplitPos + _pSplitter->GetSizePixel().Width();
    2818           0 :     fileViewPos.X() = nNewX;
    2819           0 :     Size fileViewSize = _pFileView->GetSizePixel();
    2820           0 :     fileViewSize.Width() -= ( nNewX - nOldX );
    2821           0 :     _pFileView->SetPosSizePixel( fileViewPos, fileViewSize );
    2822             : 
    2823           0 :     _pSplitter->SetPosPixel( Point( placeSize.Width(), _pSplitter->GetPosPixel().Y() ) );
    2824           0 :     return 0;
    2825             : }
    2826             : 
    2827           0 : QueryFolderNameDialog::QueryFolderNameDialog(vcl::Window* _pParent,
    2828             :     const OUString& rTitle, const OUString& rDefaultText, OUString* pGroupName)
    2829           0 :     : ModalDialog(_pParent, "FolderNameDialog", "fps/ui/foldernamedialog.ui")
    2830             : {
    2831           0 :     get(m_pNameEdit, "entry");
    2832           0 :     get(m_pNameLine, "frame");
    2833           0 :     get(m_pOKBtn, "ok");
    2834             : 
    2835           0 :     SetText( rTitle );
    2836           0 :     m_pNameEdit->SetText( rDefaultText );
    2837           0 :     m_pNameEdit->SetSelection( Selection( 0, rDefaultText.getLength() ) );
    2838           0 :     m_pOKBtn->SetClickHdl( LINK( this, QueryFolderNameDialog, OKHdl ) );
    2839           0 :     m_pNameEdit->SetModifyHdl( LINK( this, QueryFolderNameDialog, NameHdl ) );
    2840             : 
    2841           0 :     if (pGroupName)
    2842           0 :         m_pNameLine->set_label( *pGroupName );
    2843           0 : };
    2844             : 
    2845           0 : QueryFolderNameDialog::~QueryFolderNameDialog()
    2846             : {
    2847           0 :     disposeOnce();
    2848           0 : }
    2849             : 
    2850           0 : void QueryFolderNameDialog::dispose()
    2851             : {
    2852           0 :     m_pNameEdit.clear();
    2853           0 :     m_pNameLine.clear();
    2854           0 :     m_pOKBtn.clear();
    2855           0 :     ModalDialog::dispose();
    2856           0 : }
    2857             : 
    2858           0 : IMPL_LINK_NOARG(QueryFolderNameDialog, OKHdl)
    2859             : {
    2860             :     // trim the strings
    2861           0 :     m_pNameEdit->SetText(comphelper::string::strip(m_pNameEdit->GetText(), ' '));
    2862           0 :     EndDialog( RET_OK );
    2863           0 :     return 1;
    2864             : }
    2865             : 
    2866             : 
    2867           0 : IMPL_LINK_NOARG(QueryFolderNameDialog, NameHdl)
    2868             : {
    2869             :     // trim the strings
    2870           0 :     OUString aName = comphelper::string::strip(m_pNameEdit->GetText(), ' ');
    2871           0 :     if ( !aName.isEmpty() )
    2872             :     {
    2873           0 :         if ( !m_pOKBtn->IsEnabled() )
    2874           0 :             m_pOKBtn->Enable( true );
    2875             :     }
    2876             :     else
    2877             :     {
    2878           0 :         if ( m_pOKBtn->IsEnabled() )
    2879           0 :             m_pOKBtn->Enable( false );
    2880             :     }
    2881             : 
    2882           0 :     return 0;
    2883           3 : }
    2884             : 
    2885             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11