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

Generated by: LCOV version 1.10