1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
31 // includes --------------------------------------------------------------
34 #include <tools/stream.hxx>
35 #include <tools/urlobj.hxx>
36 #include <vcl/fixed.hxx>
37 #include <vcl/lstbox.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/timer.hxx>
41 #include <unotools/ucbhelper.hxx>
42 #include <ucbhelper/contentbroker.hxx>
43 #include "svtools/ehdl.hxx"
44 #include "svl/urihelper.hxx"
45 #include "unotools/pathoptions.hxx"
46 #include "unotools/viewoptions.hxx"
47 #include "svtools/fileview.hxx"
48 #include "unotools/inetoptions.hxx"
49 #include "svtools/sfxecode.hxx"
50 #include "svl/svarray.hxx"
51 #include "svtools/svtabbx.hxx"
53 #define _SVSTDARR_USHORTS
54 #define _SVSTDARR_STRINGSDTOR
55 #include "svl/svstdarr.hxx"
56 #include <toolkit/helper/vclunohelper.hxx>
57 #include <unotools/localfilehelper.hxx>
60 #include "svtools/svtools.hrc"
62 #ifndef _SVT_HELPID_HRC
63 #include "svtools/helpid.hrc"
65 #ifndef _SVTOOLS_IODLGIMPL_HRC
68 #include "rtl/instance.hxx"
69 #include "asyncfilepicker.hxx"
70 #include "iodlgimp.hxx"
71 #include "svtools/inettbc.hxx"
72 #include "unotools/syslocale.hxx"
73 #include "svtools/QueryFolderName.hxx"
74 #ifndef _RTL_USTRING_HXX
75 #include <rtl/ustring.hxx>
77 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
78 #include <com/sun/star/ucb/XContentProviderManager.hpp>
79 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
80 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
81 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
82 #include <com/sun/star/beans/PropertyValue.hpp>
83 #include <com/sun/star/sdbc/XResultSet.hpp>
84 #include <com/sun/star/sdbc/XRow.hpp>
85 #include <com/sun/star/util/URL.hpp>
86 #include <com/sun/star/uno/Exception.hpp>
87 #include <com/sun/star/uno/Reference.hxx>
88 #include <com/sun/star/util/XURLTransformer.hpp>
89 #include <com/sun/star/uno/RuntimeException.hpp>
90 #include <com/sun/star/beans/XPropertySet.hpp>
92 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
93 #include <comphelper/processfactory.hxx>
96 #include <vcl/waitobj.hxx>
98 // #97148# ------------------------------------
99 #include <com/sun/star/task/XInteractionHandler.hpp>
100 #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
101 #include "fpinteraction.hxx"
102 #include <osl/process.h>
103 #include <comphelper/interaction.hxx>
106 #include <functional>
108 //#define AUTOSELECT_USERFILTER
109 // define this for the experimental feature of user-filter auto selection
110 // means if the user enters e.g. *.doc<enter>, and there is a filter which is responsible for *.doc files (only),
111 // then this filter is selected automatically
113 using namespace ::com::sun::star::beans
;
114 using namespace ::com::sun::star::frame
;
115 using namespace ::com::sun::star::ui::dialogs
;
116 using namespace ::com::sun::star::uno
;
117 using namespace ::com::sun::star::lang
;
118 using namespace ::com::sun::star::ucb
;
119 using namespace ::com::sun::star::container
;
120 using namespace ::com::sun::star::task
;
121 using namespace ::com::sun::star::sdbc
;
122 using namespace ::utl
;
123 using namespace ::svt
;
125 using namespace ExtendedFilePickerElementIds
;
126 using namespace CommonFilePickerElementIds
;
127 using namespace InternalFilePickerElementIds
;
129 #define IODLG_CONFIGNAME String(RTL_CONSTASCII_USTRINGPARAM("FileDialog"))
130 #define IMPGRF_CONFIGNAME String(RTL_CONSTASCII_USTRINGPARAM("ImportGraphicDialog"))
132 #define GET_DECODED_NAME(aObj) \
133 aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET )
135 // Zeit die beim Traveln in der Filterbox gewartet wird,
136 // bis in der Browsebox gefiltert wird ( in ms ).
137 #define TRAVELFILTER_TIMEOUT 750
139 #define WIDTH_ADDITION 15
141 // functions -------------------------------------------------------------
146 //-----------------------------------------------------------------------------
147 String
getMostCurrentFilter( SvtExpFileDlg_Impl
* pImpl
)
149 DBG_ASSERT( pImpl
, "invalid impl pointer" );
150 const SvtFileDialogFilter_Impl
* pFilter
= pImpl
->_pUserFilter
;
153 pFilter
= pImpl
->GetCurFilter();
159 return pFilter
->GetType();
162 //-----------------------------------------------------------------------------
163 sal_Bool
restoreCurrentFilter( SvtExpFileDlg_Impl
* _pImpl
)
165 DBG_ASSERT( _pImpl
->GetCurFilter(), "restoreCurrentFilter: no current filter!" );
166 DBG_ASSERT( _pImpl
->GetCurFilterDisplayName().Len(), "restoreCurrentFilter: no current filter (no display name)!" );
168 _pImpl
->SelectFilterListEntry( _pImpl
->GetCurFilterDisplayName() );
171 String sSelectedDisplayName
;
172 DBG_ASSERT( ( _pImpl
->GetSelectedFilterEntry( sSelectedDisplayName
) == _pImpl
->GetCurFilter() )
173 && ( sSelectedDisplayName
== _pImpl
->GetCurFilterDisplayName() ),
174 "restoreCurrentFilter: inconsistence!" );
176 return _pImpl
->m_bNeedDelayedFilterExecute
;
179 //-----------------------------------------------------------------------------
180 String
GetFsysExtension_Impl( const String
& rFile
, const String
& rLastFilterExt
)
182 xub_StrLen nDotPos
= rFile
.SearchBackward( '.' );
183 if ( nDotPos
!= STRING_NOTFOUND
)
185 if ( rLastFilterExt
.Len() )
187 if ( rFile
.Copy( nDotPos
+ 1 ).EqualsIgnoreCaseAscii( rLastFilterExt
) )
188 return String( rLastFilterExt
);
191 return String( rFile
.Copy( nDotPos
) );
196 //-----------------------------------------------------------------------------
197 void SetFsysExtension_Impl( String
& rFile
, const String
& rExtension
)
199 const sal_Unicode
* p0
= rFile
.GetBuffer();
200 const sal_Unicode
* p1
= p0
+ rFile
.Len() - 1;
201 while ( p1
>= p0
&& *p1
!= sal_Unicode( '.' ) )
204 // remove old extension
206 sal::static_int_cast
< xub_StrLen
>(
207 p1
- p0
+ 1 - ( rExtension
.Len() > 0 ? 0 : 1 ) ) );
208 else if ( rExtension
.Len() )
210 rFile
+= sal_Unicode( '.' );
214 //-----------------------------------------------------------------------------
215 // move the control with the given offset
216 void lcl_MoveControl( Control
* _pControl
, sal_Int32 _nDeltaX
, sal_Int32 _nDeltaY
, sal_Int32
* _pMaxY
= NULL
)
220 Point aNewPos
= _pControl
->GetPosPixel();
222 // adjust the vertical position
223 aNewPos
.Y() += _nDeltaY
;
224 if ( _pMaxY
&& ( aNewPos
.Y() > *_pMaxY
) )
225 *_pMaxY
= aNewPos
.Y();
227 // adjust the horizontal position
228 aNewPos
.X() += _nDeltaX
;
230 _pControl
->SetPosPixel( aNewPos
);
234 //-------------------------------------------------------------------------
235 void lcl_autoUpdateFileExtension( SvtFileDialog
* _pDialog
, const String
& _rLastFilterExt
)
237 // if auto extension is enabled ....
238 if ( _pDialog
->isAutoExtensionEnabled() )
240 // automatically switch to the extension of the (maybe just newly selected) extension
241 String aNewFile
= _pDialog
->getCurrentFileText( );
242 String aExt
= GetFsysExtension_Impl( aNewFile
, _rLastFilterExt
);
244 // but only if there already is an extension
247 // check if it is a real file extension, and not only the "post-dot" part in
249 // 28.03.2002 - 98337 - fs@openoffice.org
250 sal_Bool bRealExtensions
= sal_True
;
251 if ( STRING_NOTFOUND
!= aExt
.Search( '/' ) )
252 bRealExtensions
= sal_False
;
253 else if ( STRING_NOTFOUND
!= aExt
.Search( '\\' ) )
254 bRealExtensions
= sal_False
;
257 // no easy way to tell, because the part containing the dot already is the last
258 // segment of the complete file name
259 // So we have to check if the file name denotes a folder or a file.
260 // For performance reasons, we do this for file urls only
261 INetURLObject
aURL( aNewFile
);
262 if ( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
265 if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aNewFile
, sURL
) )
266 aURL
= INetURLObject( sURL
);
268 if ( INET_PROT_FILE
== aURL
.GetProtocol() )
270 // #97148# & #102204# -----
273 bRealExtensions
= !_pDialog
->ContentIsFolder( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
275 catch( ::com::sun::star::uno::Exception
& )
277 DBG_WARNING( "Exception in lcl_autoUpdateFileExtension" );
282 if ( bRealExtensions
)
284 SetFsysExtension_Impl( aNewFile
, _pDialog
->GetDefaultExt() );
285 _pDialog
->setCurrentFileText( aNewFile
);
291 //-------------------------------------------------------------------------
292 sal_Bool
lcl_getHomeDirectory( const String
& _rForURL
, String
& /* [out] */ _rHomeDir
)
296 // now ask the content broker for a provider for this scheme
297 //=================================================================
300 // get the content provider manager
301 ::ucbhelper::ContentBroker
* pBroker
= ::ucbhelper::ContentBroker::get();
302 Reference
< XContentProviderManager
> xProviderManager
;
304 xProviderManager
= pBroker
->getContentProviderManagerInterface();
306 //=================================================================
307 // get the provider for the current scheme
308 Reference
< XContentProvider
> xProvider
;
309 if ( xProviderManager
.is() )
310 xProvider
= xProviderManager
->queryContentProvider( _rForURL
);
312 DBG_ASSERT( xProvider
.is(), "lcl_getHomeDirectory: could not find a (valid) content provider for the current URL!" );
313 Reference
< XPropertySet
> xProviderProps( xProvider
, UNO_QUERY
);
314 if ( xProviderProps
.is() )
316 Reference
< XPropertySetInfo
> xPropInfo
= xProviderProps
->getPropertySetInfo();
317 const ::rtl::OUString
sHomeDirPropertyName( RTL_CONSTASCII_USTRINGPARAM( "HomeDirectory" ) );
318 if ( !xPropInfo
.is() || xPropInfo
->hasPropertyByName( sHomeDirPropertyName
) )
320 ::rtl::OUString sHomeDirectory
;
321 xProviderProps
->getPropertyValue( sHomeDirPropertyName
) >>= sHomeDirectory
;
322 _rHomeDir
= sHomeDirectory
;
326 catch( const Exception
& )
328 DBG_ERROR( "lcl_getHomeDirectory: caught an exception!" );
330 return 0 < _rHomeDir
.Len();
333 //---------------------------------------------------------------------
334 static String
lcl_ensureFinalSlash( const String
& _rDir
)
336 INetURLObject
aWorkPathObj( _rDir
, INET_PROT_FILE
);
337 aWorkPathObj
.setFinalSlash();
338 return aWorkPathObj
.GetMainURL( INetURLObject::NO_DECODE
);
341 //---------------------------------------------------------------------
342 void convertStringListToUrls( const String
& _rColonSeparatedList
, ::std::vector
< String
>& _rTokens
, bool _bFinalSlash
)
344 const sal_Unicode s_cSeparator
=
345 #if defined(WNT) || defined(OS2)
351 xub_StrLen nTokens
= _rColonSeparatedList
.GetTokenCount( s_cSeparator
);
352 _rTokens
.resize( 0 ); _rTokens
.reserve( nTokens
);
353 for ( xub_StrLen i
=0; i
<nTokens
; ++i
)
355 // the current token in the list
356 String sCurrentToken
= _rColonSeparatedList
.GetToken( i
, s_cSeparator
);
357 if ( !sCurrentToken
.Len() )
360 INetURLObject aCurrentURL
;
363 if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken
, sURL
) )
364 aCurrentURL
= INetURLObject( sURL
);
367 // smart URL parsing, assuming FILE protocol
368 aCurrentURL
= INetURLObject( sCurrentToken
, INET_PROT_FILE
);
372 aCurrentURL
.setFinalSlash( );
374 aCurrentURL
.removeFinalSlash( );
375 _rTokens
.push_back( aCurrentURL
.GetMainURL( INetURLObject::NO_DECODE
) );
379 //---------------------------------------------------------------------
380 struct RemoveFinalSlash
: public ::std::unary_function
< String
, void >
382 void operator()( String
& _rURL
)
384 INetURLObject
aURL( _rURL
);
385 #if defined(WNT) || defined(OS2)
386 if ( aURL
.getSegmentCount() > 1 )
388 aURL
.removeFinalSlash( );
389 _rURL
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
393 // -----------------------------------------------------------------------
394 /** retrieves the value of an environment variable
395 @return <TRUE/> if and only if the retrieved string value is not empty
397 bool getEnvironmentValue( const sal_Char
* _pAsciiEnvName
, ::rtl::OUString
& _rValue
)
399 _rValue
= ::rtl::OUString();
400 ::rtl::OUString sEnvName
= ::rtl::OUString::createFromAscii( _pAsciiEnvName
);
401 osl_getEnvironment( sEnvName
.pData
, &_rValue
.pData
);
402 return _rValue
.getLength() != 0;
406 //***************************************************************************
408 //***************************************************************************
410 struct ControlChain_Impl
413 ControlChain_Impl
* _pNext
;
414 sal_Bool _bHasOwnerShip
;
416 ControlChain_Impl( Window
* pControl
, ControlChain_Impl
* pNext
);
417 ~ControlChain_Impl();
420 //***************************************************************************
422 ControlChain_Impl::ControlChain_Impl
425 ControlChain_Impl
* pNext
427 : _pControl( pControl
),
429 _bHasOwnerShip( sal_True
)
433 //***************************************************************************
435 ControlChain_Impl::~ControlChain_Impl()
437 if ( _bHasOwnerShip
)
444 //*****************************************************************************
446 //*****************************************************************************
451 ResMgr
* operator ()()
453 return ResMgr::CreateResMgr (CREATEVERSIONRESMGR_NAME(fps_office
));
456 static ResMgr
* getOrCreate()
459 ResMgr
, ResMgrHolder
,
460 osl::MutexGuard
, osl::GetGlobalMutex
>::create (
461 ResMgrHolder(), osl::GetGlobalMutex());
465 struct SvtResId
: public ResId
467 SvtResId (sal_uInt16 nId
) : ResId (nId
, *ResMgrHolder::getOrCreate()) {}
471 //*****************************************************************************
473 //*****************************************************************************
474 SvtFileDialog::SvtFileDialog
480 ModalDialog( _pParent
, SvtResId( DLG_SVT_EXPLORERFILE
) )
482 ,_pUserControls( NULL
)
483 ,_pCbReadOnly( NULL
)
485 ,_pCbPreviewBox( NULL
)
486 ,_pCbSelection( NULL
)
491 ,_pFileNotifier( NULL
)
492 ,_pImp( new SvtExpFileDlg_Impl( nBits
) )
493 ,_nExtraBits( nExtraBits
)
494 ,_bIsInExecute( sal_False
)
495 ,m_bInExecuteAsync( false )
496 ,m_bHasFilename( false )
501 //*****************************************************************************
503 SvtFileDialog::SvtFileDialog ( Window
* _pParent
, WinBits nBits
)
504 :ModalDialog( _pParent
, SvtResId( DLG_SVT_EXPLORERFILE
) )
505 ,_pUserControls( NULL
)
506 ,_pCbReadOnly( NULL
)
508 ,_pCbPreviewBox( NULL
)
509 ,_pCbSelection( NULL
)
514 ,_pFileNotifier( NULL
)
515 ,_pImp( new SvtExpFileDlg_Impl( nBits
) )
517 ,_bIsInExecute( sal_False
)
518 ,m_bHasFilename( false )
523 //*****************************************************************************
525 SvtFileDialog::~SvtFileDialog()
527 if ( _pImp
->_aIniKey
.Len() )
530 SvtViewOptions
aDlgOpt( E_DIALOG
, _pImp
->_aIniKey
);
531 aDlgOpt
.SetWindowState( String( GetWindowState(), osl_getThreadTextEncoding() ) );
532 String sUserData
= _pFileView
->GetConfigString();
533 aDlgOpt
.SetUserItem( ::rtl::OUString::createFromAscii( "UserData" ),
534 makeAny( ::rtl::OUString( sUserData
) ) );
537 _pFileView
->SetSelectHdl( Link() );
544 delete _pCbPreviewBox
;
545 delete _pCbSelection
;
550 delete _pUserControls
;
553 //*****************************************************************************
555 void SvtFileDialog::Init_Impl
560 sal_Bool bIsHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
561 m_aImages
= ImageList( SvtResId( bIsHighContrast
? RID_FILEPICKER_IMAGES_HC
: RID_FILEPICKER_IMAGES
) );
563 _pImp
->_nStyle
= nStyle
;
564 _pImp
->_a6Size
= LogicToPixel( Size( 6, 6 ), MAP_APPFONT
);
565 _pImp
->_eMode
= ( nStyle
& WB_SAVEAS
) ? FILEDLG_MODE_SAVE
: FILEDLG_MODE_OPEN
;
566 _pImp
->_eDlgType
= FILEDLG_TYPE_FILEDLG
;
568 if ( ( nStyle
& SFXWB_PATHDIALOG
) == SFXWB_PATHDIALOG
)
569 _pImp
->_eDlgType
= FILEDLG_TYPE_PATHDLG
;
571 // Set the directory for the "back to the default dir" button
572 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
573 SetStandardDir( aStdDirObj
.GetMainURL( INetURLObject::NO_DECODE
) );
575 // Reichweite bestimmen.
576 if ( !( nStyle
& SFXWB_NOREMOTE
) )
578 _pImp
->_nState
|= FILEDLG_STATE_REMOTE
;
581 // Kontrollelement erzeugen, wobei die Reihenfolge die Tab-Steuerung
583 _pImp
->_pFtFileName
= new FixedText( this, SvtResId( FT_EXPLORERFILE_FILENAME
) );
585 SvtURLBox
* pURLBox
= new SvtURLBox( this );
586 pURLBox
->SetUrlFilter( &m_aURLFilter
);
587 _pImp
->_pEdFileName
= pURLBox
;
589 Edit
aDummy( this, SvtResId( ED_EXPLORERFILE_FILENAME
) );
590 _pImp
->_pEdFileName
->SetPosSizePixel( aDummy
.GetPosPixel(), aDummy
.GetSizePixel() );
591 _pImp
->_pEdFileName
->Show();
592 pURLBox
->SetSelectHdl( LINK( this, SvtFileDialog
, EntrySelectHdl_Impl
) );
593 pURLBox
->SetOpenHdl( STATIC_LINK( this, SvtFileDialog
, OpenHdl_Impl
) );
595 // in folder picker mode, only auto-complete directories (no files)
596 bool bIsFolderPicker
= ( _pImp
->_eDlgType
== FILEDLG_TYPE_PATHDLG
);
597 pURLBox
->SetOnlyDirectories( bIsFolderPicker
);
599 // in save mode, don't use the autocompletion as selection in the edit part
600 bool bSaveMode
= ( FILEDLG_MODE_SAVE
== _pImp
->_eMode
);
601 pURLBox
->SetNoURLSelection( bSaveMode
);
603 _pImp
->_pEdFileName
->SetHelpId( HID_FILEDLG_AUTOCOMPLETEBOX
);
605 _pImp
->_pFtFileType
= new FixedText( this, SvtResId( FT_EXPLORERFILE_FILETYPE
) );
606 _pImp
->CreateFilterListControl( this, SvtResId( LB_EXPLORERFILE_FILETYPE
) );
608 // move the filter listbox to the space occupied by the version listbox
609 // if that box isn't needed
610 if ( !( _nExtraBits
& SFX_EXTRA_SHOWVERSIONS
) &&
611 !( _nExtraBits
& SFX_EXTRA_TEMPLATES
) &&
612 !( _nExtraBits
& SFX_EXTRA_IMAGE_TEMPLATE
) )
615 FixedText
aSharedListBoxLabel( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
616 _pImp
->_pFtFileType
->SetPosPixel( aSharedListBoxLabel
.GetPosPixel() );
620 ListBox
aSharedListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
621 _pImp
->GetFilterListControl()->SetPosPixel( aSharedListBox
.GetPosPixel() );
625 _pImp
->_pFtCurrentPath
= new FixedText( this, SvtResId( FT_EXPLORERFILE_CURRENTPATH
) );
626 WinBits nTmpStyle
= _pImp
->_pFtCurrentPath
->GetStyle();
627 nTmpStyle
|= WB_PATHELLIPSIS
;
628 _pImp
->_pFtCurrentPath
->SetStyle( nTmpStyle
);
630 _pImp
->_pBtnFileOpen
= new PushButton( this, SvtResId( BTN_EXPLORERFILE_OPEN
) );
631 _pImp
->_pBtnCancel
= new CancelButton( this, SvtResId( BTN_EXPLORERFILE_CANCEL
) );
632 _pImp
->_pBtnHelp
= new HelpButton( this, SvtResId( BTN_EXPLORERFILE_HELP
) );
634 _pImp
->_pBtnUp
= new SvtUpButton_Impl( this, SvtResId( BTN_EXPLORERFILE_UP
) );
635 _pImp
->_pBtnNewFolder
= new ImageButton( this, SvtResId( BTN_EXPLORERFILE_NEWFOLDER
) );
636 _pImp
->_pBtnNewFolder
->SetStyle( _pImp
->_pBtnNewFolder
->GetStyle() | WB_NOPOINTERFOCUS
);
637 _pImp
->_pBtnStandard
= new SvtTravelButton_Impl( this, SvtResId( BTN_EXPLORERFILE_STANDARD
) );
639 _pImp
->_pBtnUp
->SetAccessibleName( _pImp
->_pBtnUp
->GetQuickHelpText() );
640 _pImp
->_pBtnNewFolder
->SetAccessibleName( _pImp
->_pBtnNewFolder
->GetQuickHelpText() );
641 _pImp
->_pBtnStandard
->SetAccessibleName( _pImp
->_pBtnStandard
->GetQuickHelpText() );
643 if ( ( nStyle
& SFXWB_MULTISELECTION
) == SFXWB_MULTISELECTION
)
644 _pImp
->_bMultiSelection
= sal_True
;
646 _pFileView
= new SvtFileView( this, SvtResId( CTL_EXPLORERFILE_FILELIST
),
647 FILEDLG_TYPE_PATHDLG
== _pImp
->_eDlgType
,
648 _pImp
->_bMultiSelection
);
649 _pFileView
->SetUrlFilter( &m_aURLFilter
);
650 _pFileView
->EnableAutoResize();
652 _pFileView
->SetHelpId( HID_FILEDLG_STANDARD
);
653 _pFileView
->SetStyle( _pFileView
->GetStyle() | WB_TABSTOP
);
655 // Positionen und Groessen der Knoepfe bestimmen.
656 Image
aNewFolderImg( GetButtonImage( IMG_FILEDLG_CREATEFOLDER
) );
657 _pImp
->_pBtnNewFolder
->SetModeImage( aNewFolderImg
);
659 Size
aSize( aNewFolderImg
.GetSizePixel() );
660 aSize
.Width() += FILEDIALOG_DEF_IMAGEBORDER
;
661 aSize
.Height() += FILEDIALOG_DEF_IMAGEBORDER
;
662 _pImp
->_pBtnNewFolder
->SetSizePixel( aSize
);
663 _pImp
->_pBtnUp
->SetSizePixel( aSize
);
664 _pImp
->_pBtnStandard
->SetSizePixel( aSize
);
666 Size aDlgSize
= GetOutputSizePixel();
667 long n6AppFontInPixel
=
668 LogicToPixel( Size( 6, 0 ), MAP_APPFONT
).Width();
669 long n3AppFontInPixel
=
670 LogicToPixel( Size( 3, 0 ), MAP_APPFONT
).Width();
672 // calculate the length of all buttons
673 const sal_uInt16 nBtnCount
= 3; // "previous level", "new folder" and "standard dir"
674 long nDelta
= n6AppFontInPixel
; // right border
675 nDelta
+= ( nBtnCount
* aSize
.Width() ); // button count * button width
676 nDelta
+= ( n3AppFontInPixel
+ n3AppFontInPixel
/ 2 ); // spacing 1*big 1*small
679 aDlgSize
.Width() - nDelta
,
680 _pImp
->_pBtnUp
->GetPosPixel().Y()
683 aPos
.X() - n6AppFontInPixel
,
684 _pImp
->_pFtCurrentPath
->GetOutputSizePixel().Height()
686 _pImp
->_pFtCurrentPath
->SetOutputSizePixel( aCurPathSize
);
687 _pImp
->_pBtnUp
->SetPosPixel( aPos
);
688 aPos
.X() += aSize
.Width();
689 aPos
.X() += n3AppFontInPixel
;
690 _pImp
->_pBtnNewFolder
->SetPosPixel( aPos
);
691 aPos
.X() += aSize
.Width();
692 aPos
.X() += n3AppFontInPixel
/ 2;
693 _pImp
->_pBtnStandard
->SetPosPixel( aPos
);
694 nDelta
= aSize
.Height();
695 nDelta
-= aCurPathSize
.Height();
697 Point aCurPathPos
= _pImp
->_pFtCurrentPath
->GetPosPixel();
698 aCurPathPos
.Y() += nDelta
;
699 _pImp
->_pFtCurrentPath
->SetPosPixel( aCurPathPos
);
701 if ( nStyle
& SFXWB_READONLY
)
703 _pCbReadOnly
= new CheckBox( this, SvtResId( CB_EXPLORERFILE_READONLY
) );
704 _pCbReadOnly
->SetHelpId( HID_FILEOPEN_READONLY
);
705 _pCbReadOnly
->SetText( SvtResId( STR_SVT_FILEPICKER_READONLY
) );
706 AddControl( _pCbReadOnly
);
707 ReleaseOwnerShip( _pCbReadOnly
);
708 _pCbReadOnly
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
711 if ( nStyle
& SFXWB_PASSWORD
)
713 _pImp
->_pCbPassword
= new CheckBox( this, SvtResId( CB_EXPLORERFILE_PASSWORD
) );
714 _pImp
->_pCbPassword
->SetText( SvtResId( STR_SVT_FILEPICKER_PASSWORD
) );
715 AddControl( _pImp
->_pCbPassword
);
716 ReleaseOwnerShip( _pImp
->_pCbPassword
);
717 _pImp
->_pCbPassword
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
720 // set the ini file for extracting the size
721 _pImp
->_aIniKey
= IODLG_CONFIGNAME
;
725 // Zahl der Pixel bestimmen, um die die anderen Elemente in der Position
726 // Angepasst werden muessen.
727 aPos
.Y() += aSize
.Height();
728 aPos
.Y() += LogicToPixel( Size( 0, 6 ), MAP_APPFONT
).Height();
729 long nYOffset
= aPos
.Y();
730 aPos
= _pFileView
->GetPosPixel();
731 nYOffset
-= aPos
.Y();
733 // Positionen der uebrigen Elemente anpassen.
734 aPos
.Y() += nYOffset
;
735 _pFileView
->SetPosPixel( aPos
);
737 lcl_MoveControl( _pImp
->_pFtFileName
, 0, nYOffset
);
738 lcl_MoveControl( _pImp
->_pEdFileName
, 0, nYOffset
);
740 lcl_MoveControl( _pImp
->_pFtFileVersion
, 0, nYOffset
);
741 lcl_MoveControl( _pImp
->_pLbFileVersion
, 0, nYOffset
);
743 lcl_MoveControl( _pImp
->_pFtTemplates
, 0, nYOffset
);
744 lcl_MoveControl( _pImp
->_pLbTemplates
, 0, nYOffset
);
746 lcl_MoveControl( _pImp
->_pFtImageTemplates
, 0, nYOffset
);
747 lcl_MoveControl( _pImp
->_pLbImageTemplates
, 0, nYOffset
);
749 lcl_MoveControl( _pImp
->_pFtFileType
, 0, nYOffset
);
750 lcl_MoveControl( _pImp
->GetFilterListControl(), 0, nYOffset
);
752 lcl_MoveControl( _pImp
->_pBtnFileOpen
, 0, nYOffset
);
753 lcl_MoveControl( _pImp
->_pBtnCancel
, 0, nYOffset
);
755 lcl_MoveControl( _pImp
->_pBtnHelp
, 0, nYOffset
+ 3 );
756 // a little more spacing between Cancel- and HelpButton
758 // Groesse des Dialoges anpassen.
759 aSize
= GetSizePixel();
760 aSize
.Height() += nYOffset
;
761 SetSizePixel( aSize
);
763 // Beschriftungen dem Modus anpassen.
764 sal_uInt16 nResId
= STR_EXPLORERFILE_OPEN
;
765 sal_uInt16 nButtonResId
= 0;
767 if ( nStyle
& WB_SAVEAS
)
769 nResId
= STR_EXPLORERFILE_SAVE
;
770 nButtonResId
= STR_EXPLORERFILE_BUTTONSAVE
;
773 if ( ( nStyle
& SFXWB_PATHDIALOG
) == SFXWB_PATHDIALOG
)
775 _pImp
->_pFtFileName
->SetText( SvtResId( STR_PATHNAME
) );
776 nResId
= STR_PATHSELECT
;
777 nButtonResId
= STR_BUTTONSELECT
;
780 SetText( SvtResId( nResId
) );
783 _pImp
->_pBtnFileOpen
->SetText( SvtResId( nButtonResId
) );
785 if ( FILEDLG_TYPE_FILEDLG
!= _pImp
->_eDlgType
)
787 _pImp
->_pFtFileType
->Hide();
788 _pImp
->GetFilterListControl()->Hide();
791 // Einstellungen der Steuerelemente vornehmen.
792 _pImp
->_pBtnNewFolder
->SetClickHdl( STATIC_LINK( this, SvtFileDialog
, NewFolderHdl_Impl
) );
793 _pImp
->_pBtnFileOpen
->SetClickHdl( STATIC_LINK( this, SvtFileDialog
, OpenHdl_Impl
) );
794 _pImp
->_pBtnCancel
->SetClickHdl( LINK( this, SvtFileDialog
, CancelHdl_Impl
) );
795 _pImp
->SetFilterListSelectHdl( STATIC_LINK( this, SvtFileDialog
, FilterSelectHdl_Impl
) );
796 _pImp
->_pEdFileName
->SetGetFocusHdl( STATIC_LINK( this, SvtFileDialog
, FileNameGetFocusHdl_Impl
) );
797 _pImp
->_pEdFileName
->SetModifyHdl( STATIC_LINK( this, SvtFileDialog
, FileNameModifiedHdl_Impl
) );
798 _pFileView
->SetSelectHdl( LINK( this, SvtFileDialog
, SelectHdl_Impl
) );
799 _pFileView
->SetDoubleClickHdl( LINK( this, SvtFileDialog
, DblClickHdl_Impl
) );
800 _pFileView
->SetOpenDoneHdl( LINK( this, SvtFileDialog
, OpenDoneHdl_Impl
) );
802 // Resourcen freigeben.
805 // Timer fuer Filterbox Travel setzen
806 _pImp
->_aFilterTimer
.SetTimeout( TRAVELFILTER_TIMEOUT
);
807 _pImp
->_aFilterTimer
.SetTimeoutHdl( STATIC_LINK( this, SvtFileDialog
, FilterSelectHdl_Impl
) );
809 if ( WB_SAVEAS
& nStyle
)
811 // different help ids if in save-as mode
812 // 90744 - 09.08.2001 - frank.schoenheit@sun.com
813 SetHelpId( HID_FILESAVE_DIALOG
);
815 _pImp
->_pEdFileName
->SetHelpId( HID_FILESAVE_FILEURL
);
816 _pImp
->_pBtnFileOpen
->SetHelpId( HID_FILESAVE_DOSAVE
);
817 _pImp
->_pBtnNewFolder
->SetHelpId( HID_FILESAVE_CREATEDIRECTORY
);
818 _pImp
->_pBtnStandard
->SetHelpId( HID_FILESAVE_DEFAULTDIRECTORY
);
819 _pImp
->_pBtnUp
->SetHelpId( HID_FILESAVE_LEVELUP
);
820 _pImp
->GetFilterListControl()->SetHelpId( HID_FILESAVE_FILETYPE
);
821 _pFileView
->SetHelpId( HID_FILESAVE_FILEVIEW
);
823 // formerly, there was only _pLbFileVersion, which was used for 3 different
824 // use cases. For reasons of maintainability, I introduced extra members (_pLbTemplates, _pLbImageTemplates)
825 // for the extra use cases, and separated _pLbFileVersion
826 // I did not find out in which cases the help ID is really needed HID_FILESAVE_TEMPLATE - all
827 // tests I made lead to a dialog where _no_ of the three list boxes was present.
828 // 96930 - 15.08.2002 - fs@openoffice.org
829 if ( _pImp
->_pLbFileVersion
)
830 _pImp
->_pLbFileVersion
->SetHelpId( HID_FILESAVE_TEMPLATE
);
831 if ( _pImp
->_pLbTemplates
)
832 _pImp
->_pLbTemplates
->SetHelpId( HID_FILESAVE_TEMPLATE
);
833 if ( _pImp
->_pLbImageTemplates
)
834 _pImp
->_pLbImageTemplates
->SetHelpId( HID_FILESAVE_TEMPLATE
);
836 if ( _pImp
->_pCbPassword
) _pImp
->_pCbPassword
->SetHelpId( HID_FILESAVE_SAVEWITHPASSWORD
);
837 if ( _pImp
->_pCbAutoExtension
) _pImp
->_pCbAutoExtension
->SetHelpId( HID_FILESAVE_AUTOEXTENSION
);
838 if ( _pImp
->_pCbOptions
) _pImp
->_pCbOptions
->SetHelpId( HID_FILESAVE_CUSTOMIZEFILTER
);
839 if ( _pCbSelection
) _pCbSelection
->SetHelpId( HID_FILESAVE_SELECTION
);
842 // correct the z-order of the controls
843 implArrangeControls();
845 // special URLs, such as favourites and "restricted" paths
846 implInitializeSpecialURLLists( );
848 /// read our settings from the configuration
849 m_aConfiguration
= OConfigurationTreeRoot::createWithServiceFactory(
850 ::comphelper::getProcessServiceFactory(),
851 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI/FilePicker" ) )
855 //*****************************************************************************
857 IMPL_STATIC_LINK( SvtFileDialog
, NewFolderHdl_Impl
, PushButton
*, EMPTYARG
)
859 pThis
->_pFileView
->EndInplaceEditing( false );
861 INetURLObject
aObj( pThis
->_pFileView
->GetViewURL() );
862 String sFolderName
= aObj
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
, RTL_TEXTENCODING_UTF8
);
863 svtools::QueryFolderNameDialog
aDlg( pThis
, sFolderName
, String( SvtResId( STR_SVT_NEW_FOLDER
) ) );
864 sal_Bool bHandled
= sal_False
;
868 if ( aDlg
.Execute() == RET_OK
)
869 bHandled
= pThis
->_pFileView
->CreateNewFolder( aDlg
.GetName() );
877 //*****************************************************************************
879 IMPL_STATIC_LINK_NOINSTANCE( SvtFileDialog
, ViewHdl_Impl
, ImageButton
*, EMPTYARG
)
884 //*****************************************************************************
885 //-----------------------------------------------------------------------------
886 sal_Bool
SvtFileDialog::createNewUserFilter( const String
& _rNewFilter
, sal_Bool _bAllowUserDefExt
)
888 // delete the old user filter and create a new one
889 DELETEZ( _pImp
->_pUserFilter
);
890 _pImp
->_pUserFilter
= new SvtFileDialogFilter_Impl( _rNewFilter
, _rNewFilter
);
892 // remember the extension
893 sal_Bool bIsAllFiles
= _rNewFilter
.EqualsAscii( FILEDIALOG_FILTER_ALL
);
897 SetDefaultExt( _rNewFilter
.Copy( 2 ) );
898 // TODO: this is nonsense. In the whole file there are a lotta places where we assume that a user filter
899 // is always "*.<something>". But changing this would take some more time than I have now ...
900 // 05.12.2001 - 95486 - fs@openoffice.org
902 // now, the default extension is set to the one of the user filter (or empty)
903 // if the former is not allowed (_bAllowUserDefExt = <FALSE/>), we have to use the ext of the current filter
905 sal_Bool bUseCurFilterExt
= sal_True
;
906 String sUserFilter
= _pImp
->_pUserFilter
->GetType();
907 xub_StrLen nSepPos
= sUserFilter
.SearchBackward( '.' );
908 if ( STRING_NOTFOUND
!= nSepPos
)
910 String sUserExt
= sUserFilter
.Copy( nSepPos
+ 1 );
911 if ( ( STRING_NOTFOUND
== sUserExt
.Search( '*' ) )
912 && ( STRING_NOTFOUND
== sUserExt
.Search( '?' ) )
914 bUseCurFilterExt
= sal_False
;
917 if ( !_bAllowUserDefExt
|| bUseCurFilterExt
)
919 if ( _pImp
->GetCurFilter( ) )
920 SetDefaultExt( _pImp
->GetCurFilter( )->GetExtension() );
929 //-----------------------------------------------------------------------------
930 #define FLT_NONEMPTY 0x0001
931 #define FLT_CHANGED 0x0002
932 #define FLT_USERFILTER 0x0004
933 #define FLT_ALLFILESFILTER 0x0008
935 //-----------------------------------------------------------------------------
936 sal_uInt16
SvtFileDialog::adjustFilter( const String
& _rFilter
)
938 sal_uInt16 nReturn
= 0;
940 const sal_Bool bNonEmpty
= ( _rFilter
.Len() != 0 );
943 nReturn
|= FLT_NONEMPTY
;
945 sal_Bool bFilterChanged
= sal_True
;
947 // search for a corresponding filter
948 SvtFileDialogFilter_Impl
* pFilter
= FindFilter_Impl( _rFilter
, sal_False
, bFilterChanged
);
950 #ifdef AUTOSELECT_USERFILTER
951 // if we found a filter which without allowing multi-extensions -> select it
954 _pImp
->SelectFilterListEntry( pFilter
->GetName() );
955 _pImp
->SetCurFilter( pFilter
);
957 #endif // AUTOSELECT_USERFILTER
959 // look for multi-ext filters if necessary
961 pFilter
= FindFilter_Impl( _rFilter
, sal_True
, bFilterChanged
);
963 if ( bFilterChanged
)
964 nReturn
|= FLT_CHANGED
;
968 nReturn
|= FLT_USERFILTER
;
969 // no filter found : use it as user defined filter
970 #ifdef AUTOSELECT_USERFILTER
971 if ( createNewUserFilter( _rFilter
, sal_True
) )
973 if ( createNewUserFilter( _rFilter
, sal_False
) )
975 { // it's the "all files" filter
976 nReturn
|= FLT_ALLFILESFILTER
;
978 #ifdef AUTOSELECT_USERFILTER
979 // select the "all files" entry
980 String
sAllFilesFilter( SvtResId( STR_FILTERNAME_ALL
) );
981 if ( _pImp
->HasFilterListEntry( sAllFilesFilter
) )
983 _pImp
->SelectFilterListEntry( sAllFilesFilter
);
984 _pImp
->SetCurFilter( _pImp
->GetSelectedFilterEntry( sAllFilesFilter
) );
987 _pImp
->SetNoFilterListSelection( ); // there is no "all files" entry
988 #endif // AUTOSELECT_USERFILTER
990 #ifdef AUTOSELECT_USERFILTER
992 _pImp
->SetNoFilterListSelection( );
993 #endif // AUTOSELECT_USERFILTER
1000 //-----------------------------------------------------------------------------
1001 IMPL_LINK( SvtFileDialog
, CancelHdl_Impl
, void*, EMPTYARG
)
1003 if ( m_pCurrentAsyncAction
.is() )
1005 m_pCurrentAsyncAction
->cancel();
1006 onAsyncOperationFinished();
1010 EndDialog( sal_False
);
1015 //-----------------------------------------------------------------------------
1016 IMPL_STATIC_LINK( SvtFileDialog
, OpenHdl_Impl
, void*, pVoid
)
1018 if ( pThis
->_pImp
->_bMultiSelection
&& pThis
->_pFileView
->GetSelectionCount() > 1 )
1020 // bei Multiselektion spezielles Open
1021 pThis
->OpenMultiSelection_Impl();
1026 String
aOldPath( pThis
->_pFileView
->GetViewURL() );
1027 if ( pThis
->_pImp
->_bDoubleClick
|| pThis
->_pFileView
->HasChildPathFocus() )
1028 // Selection done by doubleclicking in the view, get filename from the view
1029 aFileName
= pThis
->_pFileView
->GetCurrentURL();
1031 if ( !aFileName
.Len() )
1033 // if an entry is selected in the view ....
1034 if ( pThis
->_pFileView
->GetSelectionCount() )
1035 { // -> use this one. This will allow us to step down this folder
1036 // #i8928# - 2002-12-20 - fs@openoffice.org
1037 aFileName
= pThis
->_pFileView
->GetCurrentURL();
1041 if ( !aFileName
.Len() )
1043 if ( pThis
->_pImp
->_eMode
== FILEDLG_MODE_OPEN
&& pThis
->_pImp
->_pEdFileName
->IsTravelSelect() )
1044 // OpenHdl called from URLBox; travelling through the list of URLs should not cause an opening
1045 return 0; // MBA->PB: seems to be called never ?!
1047 // get the URL from from the edit field ( if not empty )
1048 if ( pThis
->_pImp
->_pEdFileName
->GetText().Len() )
1050 String aText
= pThis
->_pImp
->_pEdFileName
->GetText();
1052 // did we reach the root?
1053 if ( !INetURLObject( aOldPath
).getSegmentCount() )
1055 if ( ( aText
.Len() == 2 && aText
.EqualsAscii( ".." ) ) ||
1056 ( aText
.Len() == 3 && ( aText
.EqualsAscii( "..\\" ) || aText
.EqualsAscii( "../" ) ) ) )
1057 // don't go higher than the root
1061 #if defined( UNX ) || defined( FS_PRIV_DEBUG )
1062 if ( ( 1 == aText
.Len() ) && ( '~' == aText
.GetBuffer()[0] ) )
1064 // go to the home directory
1065 if ( lcl_getHomeDirectory( pThis
->_pFileView
->GetViewURL(), aFileName
) )
1066 // in case we got a home dir, reset the text of the edit
1067 pThis
->_pImp
->_pEdFileName
->SetText( String() );
1069 if ( !aFileName
.Len() )
1072 // get url from autocomplete edit
1073 aFileName
= pThis
->_pImp
->_pEdFileName
->GetURL();
1076 else if ( pVoid
== pThis
->_pImp
->_pBtnFileOpen
)
1077 // OpenHdl was called for the "Open" Button; if edit field is empty, use selected element in the view
1078 aFileName
= pThis
->_pFileView
->GetCurrentURL();
1082 if ( !aFileName
.Len() && pVoid
== pThis
->_pImp
->_pEdFileName
&& pThis
->_pImp
->_pUserFilter
)
1084 DELETEZ( pThis
->_pImp
->_pUserFilter
);
1088 sal_uInt16 nLen
= aFileName
.Len();
1091 // if the dialog was opened to select a folder, the last selected folder should be selected
1092 if( pThis
->_pImp
->_eDlgType
== FILEDLG_TYPE_PATHDLG
)
1094 aFileName
= pThis
->_pImp
->_pFtCurrentPath
->GetText();
1095 nLen
= aFileName
.Len();
1098 // no file selected !
1102 // mark input as selected
1103 pThis
->_pImp
->_pEdFileName
->SetSelection( Selection( 0, nLen
) );
1105 // if a path with wildcards is given, divide the string into path and wildcards
1107 if ( !pThis
->IsolateFilterFromPath_Impl( aFileName
, aFilter
) )
1110 // if a filter was retrieved, there were wildcards !
1111 sal_uInt16 nNewFilterFlags
= pThis
->adjustFilter( aFilter
);
1112 if ( nNewFilterFlags
& FLT_CHANGED
)
1114 // cut off all text before wildcard in edit and select wildcard
1115 pThis
->_pImp
->_pEdFileName
->SetText( aFilter
);
1116 pThis
->_pImp
->_pEdFileName
->SetSelection( Selection( 0, aFilter
.Len() ) );
1120 INetURLObject
aFileObject( aFileName
);
1121 if ( ( aFileObject
.GetProtocol() == INET_PROT_NOT_VALID
) && aFileName
.Len() )
1123 String sCompleted
= SvtURLBox::ParseSmart( aFileName
, pThis
->_pFileView
->GetViewURL(), SvtPathOptions().GetWorkPath() );
1124 if ( sCompleted
.Len() )
1125 aFileName
= sCompleted
;
1129 // Pr"ufen, ob es sich um einen Ordner handelt.
1130 sal_Bool bIsFolder
= sal_False
;
1132 // first thing before doing anyhing with the content: Reset it. When the user presses "open" (or "save" or "export",
1133 // for that matter), s/he wants the complete handling, including all possible error messages, even if s/he
1134 // does the same thing for the same content twice, s/he wants both fails to be displayed.
1135 // Without the reset, it could be that the content cached all relevant information, and will not display any
1136 // error messages for the same content a second time ....
1137 pThis
->m_aContent
.bindTo( ::rtl::OUString( ) );
1139 // #97148# & #102204# ---------
1140 if ( aFileName
.Len() )
1142 // Make sure we have own Interaction Handler in place. We do not need
1143 // to intercept interactions here, but to record the fact that there
1144 // was an interaction.
1145 SmartContent::InteractionHandlerType eInterActionHandlerType
1146 = pThis
->m_aContent
.queryCurrentInteractionHandler();
1147 if ( ( eInterActionHandlerType
== SmartContent::IHT_NONE
) ||
1148 ( eInterActionHandlerType
== SmartContent::IHT_DEFAULT
) )
1149 pThis
->m_aContent
.enableOwnInteractionHandler(
1150 OFilePickerInteractionHandler::E_NOINTERCEPTION
);
1152 bIsFolder
= pThis
->m_aContent
.isFolder( aFileName
);
1154 // access denied to the given resource - and interaction was already
1155 // used => break following operations
1156 OFilePickerInteractionHandler
* pHandler
1157 = pThis
->m_aContent
.getOwnInteractionHandler();
1159 OSL_ENSURE( pHandler
, "Got no Interaction Handler!!!" );
1161 if ( pHandler
->wasAccessDenied() )
1164 if ( pThis
->m_aContent
.isInvalid() &&
1165 ( pThis
->_pImp
->_eMode
== FILEDLG_MODE_OPEN
) )
1167 if ( !pHandler
->wasUsed() )
1168 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS
);
1173 // restore previous Interaction Handler
1174 if ( eInterActionHandlerType
== SmartContent::IHT_NONE
)
1175 pThis
->m_aContent
.disableInteractionHandler();
1176 else if ( eInterActionHandlerType
== SmartContent::IHT_DEFAULT
)
1177 pThis
->m_aContent
.enableDefaultInteractionHandler();
1180 if ( !bIsFolder
// no existent folder
1181 && pThis
->_pImp
->_pCbAutoExtension
// auto extension is enabled in general
1182 && pThis
->_pImp
->_pCbAutoExtension
->IsChecked() // auto extension is really to be used
1183 && pThis
->GetDefaultExt().Len() // there is a default extension
1184 && pThis
->GetDefaultExt() != '*' // the default extension is not "all"
1185 && !( FILEDLG_MODE_SAVE
== pThis
->_pImp
->_eMode
// we're saving a file
1186 && pThis
->_pFileView
->GetSelectionCount() // there is a selected file in the file view -> it will later on
1187 ) // (in SvtFileDialog::GetPathList) be taken as file to save to
1188 // (#114818# - 2004-03-17 - fs@openoffice.org)
1189 && FILEDLG_MODE_OPEN
!= pThis
->_pImp
->_eMode
// pb: #i83408# don't append extension on open
1192 // check extension and append the default extension if necessary
1193 appendDefaultExtension(aFileName
,
1194 pThis
->GetDefaultExt(),
1195 pThis
->_pImp
->GetCurFilter()->GetType());
1198 sal_Bool bOpenFolder
= ( FILEDLG_TYPE_PATHDLG
== pThis
->_pImp
->_eDlgType
) &&
1199 !pThis
->_pImp
->_bDoubleClick
&& pVoid
!= pThis
->_pImp
->_pEdFileName
;
1204 pThis
->_aPath
= aFileName
;
1208 if ( aFileName
!= pThis
->_pFileView
->GetViewURL() )
1210 if ( !pThis
->m_aURLFilter
.isUrlAllowed( aFileName
) )
1212 pThis
->simulateAccessDenied( aFileName
);
1216 pThis
->OpenURL_Impl( aFileName
);
1220 if ( nNewFilterFlags
& FLT_CHANGED
)
1221 pThis
->ExecuteFilter();
1227 else if ( !( nNewFilterFlags
& FLT_NONEMPTY
) )
1229 // Ggf. URL speichern.
1230 pThis
->_aPath
= aFileName
;
1234 // Ggf. neu filtern.
1235 if ( nNewFilterFlags
& FLT_CHANGED
)
1236 pThis
->ExecuteFilter();
1240 INetURLObject
aFileObj( aFileName
);
1241 if ( aFileObj
.HasError() )
1243 ErrorHandler::HandleError( ERRCODE_IO_GENERAL
);
1247 // if restrictions for the allowed folders are in place, we need to do a check here
1248 if ( !pThis
->m_aURLFilter
.isUrlAllowed( aFileObj
.GetMainURL( INetURLObject::NO_DECODE
) ) )
1250 pThis
->simulateAccessDenied( aFileName
);
1254 switch ( pThis
->_pImp
->_eMode
)
1256 case FILEDLG_MODE_SAVE
:
1258 if ( ::utl::UCBContentHelper::Exists( aFileObj
.GetMainURL( INetURLObject::NO_DECODE
) ) )
1260 QueryBox
aBox( pThis
, WB_YES_NO
, SvtResId( STR_SVT_ALREADYEXISTOVERWRITE
) );
1261 if ( aBox
.Execute() != RET_YES
)
1267 if ( ::utl::LocalFileHelper::ConvertURLToSystemPath( aFileName
, aCurPath
) )
1269 // if content does not exist: at least its path must exist
1270 INetURLObject aPathObj
= aFileObj
;
1271 aPathObj
.removeSegment();
1272 // #97148# & #102204# ------------
1273 sal_Bool bFolder
= pThis
->m_aContent
.isFolder( aPathObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1276 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH
);
1284 case FILEDLG_MODE_OPEN
:
1286 // do an existence check herein, again
1287 // 16.11.2001 - 93107 - frank.schoenheit@sun.com
1289 if ( INET_PROT_FILE
== aFileObj
.GetProtocol( ) )
1291 sal_Bool bExists
= sal_False
;
1292 // #102204# --------------
1293 bExists
= pThis
->m_aContent
.is( aFileObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1298 String
sError( SvtResId( RID_FILEOPEN_NOTEXISTENTFILE
) );
1300 String
sInvalidFile( aFileObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
) );
1301 if ( INET_PROT_FILE
== aFileObj
.GetProtocol() )
1302 { // if it's a file URL, transform the URL into system notation
1303 ::rtl::OUString
sURL( sInvalidFile
);
1304 ::rtl::OUString sSystem
;
1305 osl_getSystemPathFromFileURL( sURL
.pData
, &sSystem
.pData
);
1306 sInvalidFile
= sSystem
;
1308 sError
.SearchAndReplaceAscii( "$name$", sInvalidFile
);
1310 ErrorBox
aError( pThis
, WB_OK
, sError
);
1319 DBG_ERROR("SvtFileDialog, OpenHdl_Impl: invalid mode!");
1322 // Interessenten benachrichtigen.
1325 if ( pThis
->_aOKHdl
.IsSet() )
1326 nRet
= pThis
->_aOKHdl
.Call( pThis
);
1332 pThis
->EndDialog( sal_True
);
1338 //*****************************************************************************
1340 void SvtFileDialog::EnableAutocompletion( sal_Bool _bEnable
)
1342 _pImp
->_pEdFileName
->EnableAutocompletion( _bEnable
);
1345 //*****************************************************************************
1347 IMPL_STATIC_LINK( SvtFileDialog
, FilterSelectHdl_Impl
, ListBox
*, pBox
)
1349 DBG_ASSERT( pBox
, "SvtFileDialog:keine Instanz" );
1351 // wurde der Handler vom Travel-Timer gefeuert?
1352 if ( pBox
== (ListBox
*)&pThis
->_pImp
->_aFilterTimer
)
1354 // Anzeige erneut filtern.
1355 pThis
->ExecuteFilter();
1359 String sSelectedFilterDisplayName
;
1360 SvtFileDialogFilter_Impl
* pSelectedFilter
= pThis
->_pImp
->GetSelectedFilterEntry( sSelectedFilterDisplayName
);
1361 if ( !pSelectedFilter
)
1362 { // there is no current selection. This happens if for instance the user selects a group separator using
1363 // the keyboard, and then presses enter: When the selection happens, we immediately deselect the entry,
1364 // so in this situation there is no current selection.
1365 if ( restoreCurrentFilter( pThis
->_pImp
) )
1366 pThis
->ExecuteFilter();
1370 if ( pSelectedFilter
->isGroupSeparator() )
1371 { // group separators can't be selected
1372 // return to the previously selected entry
1373 if ( pThis
->_pImp
->IsFilterListTravelSelect() )
1375 pThis
->_pImp
->SetNoFilterListSelection( );
1377 // stop the timer for executing the filter
1378 if ( pThis
->_pImp
->_aFilterTimer
.IsActive() )
1379 pThis
->_pImp
->m_bNeedDelayedFilterExecute
= sal_True
;
1380 pThis
->_pImp
->_aFilterTimer
.Stop();
1384 if ( restoreCurrentFilter( pThis
->_pImp
) )
1385 pThis
->ExecuteFilter();
1388 else if ( ( pSelectedFilter
!= pThis
->_pImp
->GetCurFilter() )
1389 || pThis
->_pImp
->_pUserFilter
1392 // Store the old filter for the auto extension handling
1393 String sLastFilterExt
= pThis
->_pImp
->GetCurFilter()->GetExtension();
1394 DELETEZ( pThis
->_pImp
->_pUserFilter
);
1396 // Ggf. Filter des Benutzers entfernen.
1397 pThis
->_pImp
->SetCurFilter( pSelectedFilter
, sSelectedFilterDisplayName
);
1399 // Ggf. Endung anzeigen.
1400 pThis
->SetDefaultExt( pSelectedFilter
->GetExtension() );
1401 sal_uInt16 nSepPos
= pThis
->GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP
);
1403 if ( nSepPos
!= STRING_NOTFOUND
)
1404 pThis
->EraseDefaultExt( nSepPos
);
1406 // update the extension of the current file if necessary
1407 lcl_autoUpdateFileExtension( pThis
, sLastFilterExt
);
1409 // wenn der Benutzer schnell durch die Filterbox
1410 // travelt, nicht sofort Filtern
1411 if ( pThis
->_pImp
->IsFilterListTravelSelect() )
1413 // FilterSelectHdl_Impl soll in
1414 // TRAVELFILTER_TIMEOUT ms neu gefeuert werden
1415 pThis
->_pImp
->_aFilterTimer
.Start();
1419 // evtl. vorher gestarteten Timer stoppen
1420 pThis
->_pImp
->_aFilterTimer
.Stop();
1422 // Anzeige erneut filtern.
1423 pThis
->ExecuteFilter();
1431 //*****************************************************************************
1433 IMPL_STATIC_LINK( SvtFileDialog
, FileNameGetFocusHdl_Impl
, void*, EMPTYARG
)
1435 pThis
->_pFileView
->SetNoSelection();
1436 pThis
->_pFileView
->Update();
1440 //*****************************************************************************
1442 IMPL_STATIC_LINK( SvtFileDialog
, FileNameModifiedHdl_Impl
, void*, EMPTYARG
)
1444 FileNameGetFocusHdl_Impl( pThis
, NULL
);
1448 //*****************************************************************************
1450 SvtFileDialogFilter_Impl
* SvtFileDialog::FindFilter_Impl
1452 const String
& _rFilter
,
1453 sal_Bool _bMultiExt
,/* sal_True - auch Filter mit mehreren Endungen
1455 sal_False - keine ...
1457 sal_Bool
& _rFilterChanged
1462 Die Methode sucht in den eingef"ugten Filtern nach der
1463 spezifizierten Endung.
1467 SvtFileDialogFilter_Impl
* pFoundFilter
= NULL
;
1468 SvtFileDialogFilterList_Impl
* pList
= _pImp
->_pFilter
;
1469 sal_uInt16 nFilter
= pList
->Count();
1473 SvtFileDialogFilter_Impl
* pFilter
= pList
->GetObject( nFilter
);
1474 const String
& rType
= pFilter
->GetType();
1475 String aSingleType
= rType
;
1479 sal_uInt16 nIdx
= 0;
1480 while ( !pFoundFilter
&& nIdx
!= STRING_NOTFOUND
)
1482 aSingleType
= rType
.GetToken( 0, FILEDIALOG_DEF_EXTSEP
, nIdx
);
1484 if ( aSingleType
.CompareTo( _rFilter
) == COMPARE_EQUAL
)
1486 if ( aSingleType
.CompareIgnoreCaseToAscii( _rFilter
) == COMPARE_EQUAL
)
1488 pFoundFilter
= pFilter
;
1492 else if ( rType
.CompareTo( _rFilter
) == COMPARE_EQUAL
)
1494 else if ( rType
.CompareIgnoreCaseToAscii( _rFilter
) == COMPARE_EQUAL
)
1496 pFoundFilter
= pFilter
;
1500 // Filter aktivieren.
1501 _rFilterChanged
= _pImp
->_pUserFilter
|| ( _pImp
->GetCurFilter() != pFilter
);
1503 createNewUserFilter( _rFilter
, sal_False
);
1508 return pFoundFilter
;
1511 //*****************************************************************************
1513 void SvtFileDialog::ExecuteFilter()
1515 _pImp
->m_bNeedDelayedFilterExecute
= sal_False
;
1516 executeAsync( AsyncPickerAction::eExecuteFilter
, String(), getMostCurrentFilter( _pImp
) );
1519 //*****************************************************************************
1521 void SvtFileDialog::OpenMultiSelection_Impl()
1525 OpenHandler f"ur MultiSelektion
1530 sal_uLong nCount
= _pFileView
->GetSelectionCount();
1531 SvLBoxEntry
* pEntry
= nCount
? _pFileView
->FirstSelected() : NULL
;
1533 if ( nCount
&& pEntry
)
1534 _aPath
= _pFileView
->GetURL( pEntry
);
1536 // Interessenten benachrichtigen.
1539 if ( _aOKHdl
.IsSet() )
1540 nRet
= _aOKHdl
.Call( this );
1545 EndDialog( sal_True
);
1548 //*****************************************************************************
1550 void SvtFileDialog::UpdateControls( const String
& rURL
)
1552 _pImp
->_pEdFileName
->SetBaseURL( rURL
);
1554 INetURLObject
aObj( rURL
);
1556 //=========================================================================
1559 DBG_ASSERT( INET_PROT_NOT_VALID
!= aObj
.GetProtocol(), "SvtFileDialog::UpdateControls: Invalid URL!" );
1561 if ( aObj
.getSegmentCount() )
1563 ::utl::LocalFileHelper::ConvertURLToSystemPath( rURL
, sText
);
1566 // no Fsys path for server file system ( only UCB has mountpoints! )
1567 if ( INET_PROT_FILE
!= aObj
.GetProtocol() )
1568 sText
= rURL
.Copy( static_cast< sal_uInt16
>(
1569 INetURLObject::GetScheme( aObj
.GetProtocol() ).getLength() ) );
1572 if ( !sText
.Len() && aObj
.getSegmentCount() )
1577 if ( FILEDLG_TYPE_PATHDLG
== _pImp
->_eDlgType
)
1578 // -> set new path in the edit field
1579 _pImp
->_pEdFileName
->SetText( sText
);
1581 // in the "current path" field, truncate the trailing slash
1582 if ( aObj
.hasFinalSlash() )
1584 aObj
.removeFinalSlash();
1585 String
sURL( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1586 if ( !::utl::LocalFileHelper::ConvertURLToSystemPath( sURL
, sText
) )
1590 if ( !sText
.Len() && rURL
.Len() )
1591 // happens, for instance, for URLs which the INetURLObject does not know to belong to a hierarchical scheme
1593 _pImp
->_pFtCurrentPath
->SetText( sText
);
1596 //=========================================================================
1598 if ( _pFileNotifier
)
1599 _pFileNotifier
->notify( DIRECTORY_CHANGED
, 0 );
1602 //*****************************************************************************
1604 IMPL_LINK( SvtFileDialog
, SelectHdl_Impl
, SvTabListBox
*, pBox
)
1606 SvLBoxEntry
* pEntry
= pBox
->FirstSelected();
1607 DBG_ASSERT( pEntry
, "SelectHandler without selected entry" );
1608 SvtContentEntry
* pUserData
= (SvtContentEntry
*)pEntry
->GetUserData();
1612 INetURLObject
aObj( pUserData
->maURL
);
1613 if ( FILEDLG_TYPE_PATHDLG
== _pImp
->_eDlgType
)
1615 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
1617 if ( !pUserData
->mbIsFolder
)
1618 aObj
.removeSegment();
1619 String aName
= aObj
.getFSysPath( (INetURLObject::FSysStyle
)(INetURLObject::FSYS_DETECT
& ~INetURLObject::FSYS_VOS
) );
1620 _pImp
->_pEdFileName
->SetText( aName
);
1621 _pImp
->_pEdFileName
->SetSelection( Selection( 0, aName
.Len() ) );
1622 _aPath
= pUserData
->maURL
;
1624 else if ( !pUserData
->mbIsFolder
)
1626 _pImp
->_pEdFileName
->SetText( pUserData
->maURL
);
1627 _pImp
->_pEdFileName
->SetSelection( Selection( 0, pUserData
->maURL
.Len() ) );
1628 _aPath
= pUserData
->maURL
;
1631 _pImp
->_pEdFileName
->SetText( UniString() );
1635 if ( !pUserData
->mbIsFolder
)
1637 String aName
= pBox
->GetEntryText( pEntry
, 0 );
1638 _pImp
->_pEdFileName
->SetText( aName
);
1639 _pImp
->_pEdFileName
->SetSelection( Selection( 0, aName
.Len() ) );
1640 _aPath
= pUserData
->maURL
;
1645 if ( _pImp
->_bMultiSelection
&& _pFileView
->GetSelectionCount() > 1 )
1647 // bei Multiselektion den Datei-Edit leeren
1648 _pImp
->_pEdFileName
->SetText( String() );
1656 //*****************************************************************************
1658 IMPL_LINK( SvtFileDialog
, DblClickHdl_Impl
, SvTabListBox
*, EMPTYARG
)
1660 _pImp
->_bDoubleClick
= sal_True
;
1661 OpenHdl_Impl( this, NULL
);
1662 _pImp
->_bDoubleClick
= sal_False
;
1667 //*****************************************************************************
1669 IMPL_LINK( SvtFileDialog
, EntrySelectHdl_Impl
, ComboBox
*, EMPTYARG
)
1676 //*****************************************************************************
1678 IMPL_LINK( SvtFileDialog
, OpenDoneHdl_Impl
, SvtFileView
*, pView
)
1680 String
sCurrentFolder( pView
->GetViewURL() );
1681 // check if we can create new folders
1682 EnableControl( _pImp
->_pBtnNewFolder
, ContentCanMakeFolder( sCurrentFolder
) && m_aURLFilter
.isUrlAllowed( sCurrentFolder
, false ) );
1684 // check if we can travel one level up
1685 bool bCanTravelUp
= ContentHasParentFolder( pView
->GetViewURL() );
1688 // additional check: the parent folder should not be prohibited
1689 INetURLObject
aCurrentFolder( sCurrentFolder
);
1690 DBG_ASSERT( INET_PROT_NOT_VALID
!= aCurrentFolder
.GetProtocol(),
1691 "SvtFileDialog::OpenDoneHdl_Impl: invalid current URL!" );
1693 aCurrentFolder
.removeSegment();
1694 bCanTravelUp
&= m_aURLFilter
.isUrlAllowed( aCurrentFolder
.GetMainURL( INetURLObject::NO_DECODE
) );
1696 EnableControl( _pImp
->_pBtnUp
, bCanTravelUp
);
1701 //*****************************************************************************
1703 IMPL_LINK( SvtFileDialog
, AutoExtensionHdl_Impl
, CheckBox
*, EMPTYARG
)
1705 if ( _pFileNotifier
)
1706 _pFileNotifier
->notify( CTRL_STATE_CHANGED
,
1707 CHECKBOX_AUTOEXTENSION
);
1709 // update the extension of the current file if necessary
1710 lcl_autoUpdateFileExtension( this, _pImp
->GetCurFilter()->GetExtension() );
1715 //*****************************************************************************
1717 IMPL_LINK( SvtFileDialog
, ClickHdl_Impl
, CheckBox
*, pCheckBox
)
1719 if ( ! _pFileNotifier
)
1724 if ( pCheckBox
== _pImp
->_pCbOptions
)
1725 nId
= CHECKBOX_FILTEROPTIONS
;
1726 else if ( pCheckBox
== _pCbSelection
)
1727 nId
= CHECKBOX_SELECTION
;
1728 else if ( pCheckBox
== _pCbReadOnly
)
1729 nId
= CHECKBOX_READONLY
;
1730 else if ( pCheckBox
== _pImp
->_pCbPassword
)
1731 nId
= CHECKBOX_PASSWORD
;
1732 else if ( pCheckBox
== _pCbLinkBox
)
1733 nId
= CHECKBOX_LINK
;
1734 else if ( pCheckBox
== _pCbPreviewBox
)
1735 nId
= CHECKBOX_PREVIEW
;
1738 _pFileNotifier
->notify( CTRL_STATE_CHANGED
, nId
);
1743 //*****************************************************************************
1745 IMPL_LINK( SvtFileDialog
, PlayButtonHdl_Impl
, PushButton
*, EMPTYARG
)
1747 if ( _pFileNotifier
)
1748 _pFileNotifier
->notify( CTRL_STATE_CHANGED
,
1754 //*****************************************************************************
1756 long SvtFileDialog::Notify( NotifyEvent
& rNEvt
)
1760 Die Methode wird gerufen, <BACKSPACE> abzufangen.
1764 sal_uInt16 nType
= rNEvt
.GetType();
1767 if ( EVENT_KEYINPUT
== nType
&& rNEvt
.GetKeyEvent() )
1769 const KeyCode
& rKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
1770 sal_uInt16 nCode
= rKeyCode
.GetCode();
1772 if ( !rKeyCode
.GetModifier() &&
1773 KEY_BACKSPACE
== nCode
&& !_pImp
->_pEdFileName
->HasChildPathFocus() )
1775 nRet
= 0; //! (long)_pFileView->DoBeamerKeyInput( *rNEvt.GetKeyEvent() );
1777 if ( !nRet
&& _pImp
->_pBtnUp
->IsEnabled() )
1783 // else if ( rKeyCode.IsMod1() && ( KEY_C == nCode || KEY_V == nCode || KEY_X == nCode ) )
1786 String aVerb = KEY_C == nCode ? UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_COPY)) :
1787 ( KEY_V == nCode ? UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_PASTE)) : UniString(RTL_CONSTASCII_USTRINGPARAM(SVT_MENUPART_VERB_CUT)) );
1788 //(dv) if ( !CntPopupMenu::DoVerbCommand( aVerb, _pFileView->GetView() ) )
1789 //(dv) Sound::Beep();
1793 return nRet
? nRet
: ModalDialog::Notify( rNEvt
);
1796 //*****************************************************************************
1798 long SvtFileDialog::OK()
1803 //*****************************************************************************
1805 class SvtDefModalDialogParent_Impl
1811 SvtDefModalDialogParent_Impl( Window
*pNew
) :
1812 _pOld( Application::GetDefDialogParent() )
1813 { Application::SetDefDialogParent( pNew
); }
1815 ~SvtDefModalDialogParent_Impl() { Application::SetDefDialogParent( _pOld
); }
1818 //*****************************************************************************
1820 //---------------------------------------------------------------------
1821 void SvtFileDialog::updateListboxLabelSizes()
1823 sal_Int16 nLineControlId
[5] = {
1824 LISTBOX_VERSION
, LISTBOX_TEMPLATE
, LISTBOX_IMAGE_TEMPLATE
, LISTBOX_FILTER
, EDIT_FILEURL
1827 // determine the maximum width needed for the listbox labels
1829 for ( sal_Int32 i
=0; i
<5; ++i
)
1831 FixedText
* pLabel
= static_cast< FixedText
* >( getControl( nLineControlId
[i
], sal_True
) );
1834 nMaxWidth
= ::std::max( pLabel
->GetTextWidth( pLabel
->GetText() ), nMaxWidth
);
1837 // ensure that all labels are wide enough
1838 for ( sal_Int32 i
=0; i
<5; ++i
)
1840 FixedText
* pLabel
= static_cast< FixedText
* >( getControl( nLineControlId
[i
], sal_True
) );
1841 ListBox
* pListbox
= static_cast< ListBox
* >( getControl( nLineControlId
[i
], sal_False
) );
1842 if ( !pLabel
|| !pListbox
)
1844 Size
aCurrentSize( pLabel
->GetSizePixel() );
1845 if ( aCurrentSize
.Width() >= nMaxWidth
)
1848 long nChange
= nMaxWidth
- aCurrentSize
.Width();
1849 pLabel
->SetSizePixel( Size( nMaxWidth
, aCurrentSize
.Height() ) );
1851 aCurrentSize
= pListbox
->GetSizePixel();
1852 pListbox
->SetSizePixel( Size( aCurrentSize
.Width() - nChange
, aCurrentSize
.Height() ) );
1853 lcl_MoveControl( pListbox
, nChange
, 0 );
1860 bool implIsInvalid( const String
& rURL
)
1862 SmartContent
aContent( rURL
);
1863 aContent
.enableOwnInteractionHandler( ::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST
);
1864 aContent
.isFolder(); // do this _before_ asking isInvalid! Otherwise result might be wrong.
1865 return aContent
.isInvalid();
1870 //---------------------------------------------------------------------
1871 String
SvtFileDialog::implGetInitialURL( const String
& _rPath
, const String
& _rFallback
)
1873 // an URL parser for the fallback
1874 INetURLObject aURLParser
;
1877 bool bWasAbsolute
= sal_False
;
1878 aURLParser
= aURLParser
.smartRel2Abs( _rPath
, bWasAbsolute
);
1880 // is it a valid folder?
1881 m_aContent
.bindTo( aURLParser
.GetMainURL( INetURLObject::NO_DECODE
) );
1882 sal_Bool bIsFolder
= m_aContent
.isFolder( ); // do this _before_ asking isInvalid!
1883 sal_Bool bIsInvalid
= m_aContent
.isInvalid();
1885 if ( bIsInvalid
&& m_bHasFilename
&& !aURLParser
.hasFinalSlash() )
1886 { // check if the parent folder exists
1887 // #108429# - 2003-03-26 - fs@openoffice.org
1888 INetURLObject
aParent( aURLParser
);
1889 aParent
.removeSegment( );
1890 aParent
.setFinalSlash( );
1891 bIsInvalid
= implIsInvalid( aParent
.GetMainURL( INetURLObject::NO_DECODE
) );
1896 INetURLObject
aFallback( _rFallback
);
1897 bIsInvalid
= implIsInvalid( aFallback
.GetMainURL( INetURLObject::NO_DECODE
) );
1900 aURLParser
= aFallback
;
1905 INetURLObject
aParent( aURLParser
);
1906 while ( bIsInvalid
&& aParent
.removeSegment() )
1908 aParent
.setFinalSlash( );
1909 bIsInvalid
= implIsInvalid( aParent
.GetMainURL( INetURLObject::NO_DECODE
) );
1913 aURLParser
= aParent
;
1916 if ( !bIsInvalid
&& bIsFolder
)
1918 aURLParser
.setFinalSlash();
1920 return aURLParser
.GetMainURL( INetURLObject::NO_DECODE
);
1923 //---------------------------------------------------------------------
1924 short SvtFileDialog::Execute()
1926 if ( !PrepareExecute() )
1929 // Start des Dialogs.
1930 _bIsInExecute
= sal_True
;
1931 short nResult
= ModalDialog::Execute();
1932 _bIsInExecute
= sal_False
;
1934 DBG_ASSERT( !m_pCurrentAsyncAction
.is(), "SvtFilePicker::Execute: still running an async action!" );
1935 // the dialog should not be cancellable while an async action is running - firs, the action
1936 // needs to be cancelled
1938 // letztes Verzeichnis merken
1939 if ( RET_OK
== nResult
)
1941 INetURLObject
aURL( _aPath
);
1942 if ( aURL
.GetProtocol() == INET_PROT_FILE
)
1944 // nur bei File-URL's und nicht bei virtuelle Folder
1945 // das ausgew"ahlte Verzeichnis merken
1946 sal_Int32 nLevel
= aURL
.getSegmentCount();
1947 // #97148# & #102204# ------
1948 sal_Bool bDir
= m_aContent
.isFolder( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
1949 // sal_Bool bClassPath = ( ( _pImp->_nStyle & SFXWB_CLASSPATH ) == SFXWB_CLASSPATH );
1950 if ( nLevel
> 1 && ( FILEDLG_TYPE_FILEDLG
== _pImp
->_eDlgType
|| !bDir
) )
1951 aURL
.removeSegment();
1958 //---------------------------------------------------------------------
1959 void SvtFileDialog::StartExecuteModal( const Link
& rEndDialogHdl
)
1963 // Start des Dialogs.
1964 // _bIsInExecute = sal_True;
1965 ModalDialog::StartExecuteModal( rEndDialogHdl
);
1968 //-----------------------------------------------------------------------------
1969 void SvtFileDialog::onAsyncOperationStarted()
1971 EnableUI( sal_False
);
1972 // the cancel button must be always enabled
1973 _pImp
->_pBtnCancel
->Enable( sal_True
);
1974 _pImp
->_pBtnCancel
->GrabFocus();
1977 //-----------------------------------------------------------------------------
1978 void SvtFileDialog::onAsyncOperationFinished()
1980 EnableUI( sal_True
);
1981 m_pCurrentAsyncAction
= NULL
;
1982 if ( !m_bInExecuteAsync
)
1983 _pImp
->_pEdFileName
->GrabFocus();
1984 // (if m_bInExecuteAsync is true, then the operation was finished within the minium wait time,
1985 // and to the user, the operation appears to be synchronous)
1988 //-------------------------------------------------------------------------
1989 void SvtFileDialog::displayIOException( const String
& _rURL
, IOErrorCode _eCode
)
1993 // create make a human-readable string from the URL
1994 String
sDisplayPath( _rURL
);
1995 ::utl::LocalFileHelper::ConvertURLToSystemPath( _rURL
, sDisplayPath
);
1997 // build an own exception which tells "access denied"
1998 InteractiveAugmentedIOException aException
;
1999 aException
.Arguments
.realloc( 2 );
2000 aException
.Arguments
[ 0 ] <<= ::rtl::OUString( sDisplayPath
);
2001 aException
.Arguments
[ 1 ] <<= PropertyValue(
2002 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ),
2003 -1, aException
.Arguments
[ 0 ], PropertyState_DIRECT_VALUE
2005 // (formerly, it was sufficient to put the URL first parameter. Nowadays,
2006 // the services expects the URL in a PropertyValue named "Uri" ...)
2007 aException
.Code
= _eCode
;
2008 aException
.Classification
= InteractionClassification_ERROR
;
2010 // let and interaction handler handle this exception
2011 ::comphelper::OInteractionRequest
* pRequest
= NULL
;
2012 Reference
< ::com::sun::star::task::XInteractionRequest
> xRequest
= pRequest
=
2013 new ::comphelper::OInteractionRequest( makeAny( aException
) );
2014 pRequest
->addContinuation( new ::comphelper::OInteractionAbort( ) );
2016 Reference
< XInteractionHandler
> xHandler(
2017 ::comphelper::getProcessServiceFactory()->createInstance(
2018 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") )
2022 if ( xHandler
.is() )
2023 xHandler
->handle( xRequest
);
2025 catch( const Exception
& )
2027 DBG_ERROR( "iodlg::displayIOException: caught an exception!" );
2031 //-----------------------------------------------------------------------------
2032 void SvtFileDialog::EnableUI( sal_Bool _bEnable
)
2038 for ( ::std::set
< Control
* >::iterator aLoop
= m_aDisabledControls
.begin();
2039 aLoop
!= m_aDisabledControls
.end();
2043 (*aLoop
)->Enable( sal_False
);
2048 //-----------------------------------------------------------------------------
2049 void SvtFileDialog::EnableControl( Control
* _pControl
, sal_Bool _bEnable
)
2053 DBG_ERRORFILE( "SvtFileDialog::EnableControl: invalid control!" );
2057 _pControl
->Enable( _bEnable
);
2061 ::std::set
< Control
* >::iterator aPos
= m_aDisabledControls
.find( _pControl
);
2062 if ( m_aDisabledControls
.end() != aPos
)
2063 m_aDisabledControls
.erase( aPos
);
2066 m_aDisabledControls
.insert( _pControl
);
2069 //----------------------------------------------------------------------------
2071 short SvtFileDialog::PrepareExecute()
2073 rtl::OUString aEnvValue
;
2074 if ( getEnvironmentValue( "WorkDirMustContainRemovableMedia", aEnvValue
) &&
2075 aEnvValue
.equalsAscii( "1" ) )
2079 INetURLObject
aStdDir( GetStandardDir() );
2080 ::ucbhelper::Content
aCnt( rtl::OUString( aStdDir
.GetMainURL(
2081 INetURLObject::NO_DECODE
) ),
2082 Reference
< XCommandEnvironment
>() );
2083 Sequence
< rtl::OUString
> aProps(2);
2084 aProps
[0] = rtl::OUString::createFromAscii( "IsVolume" );
2085 aProps
[1] = rtl::OUString::createFromAscii( "IsRemoveable" );
2087 Reference
< XResultSet
> xResultSet
2088 = aCnt
.createCursor( aProps
, ::ucbhelper::INCLUDE_FOLDERS_ONLY
);
2089 if ( xResultSet
.is() )
2091 Reference
< XRow
> xRow( xResultSet
, UNO_QUERY
);
2094 if ( !xResultSet
->next() )
2101 // @@@ KSO 05/18/2006: support for removable media currently hardcoded/incomplete in OSL
2105 // // check, whether child is a removable volume
2106 // if ( xRow->getBoolean( 1 ) && !xRow->wasNull() )
2108 // if ( xRow->getBoolean( 2 ) && !xRow->wasNull() )
2115 // while ( xResultSet->next() );
2120 ErrorBox
aBox( this, WB_OK
, SvtResId( STR_SVT_NOREMOVABLEDEVICE
) );
2126 catch ( ContentCreationException
const & )
2129 catch ( CommandAbortedException
const & )
2134 // #102204# ---------------
2135 if ( ( _pImp
->_nStyle
& WB_SAVEAS
) && m_bHasFilename
)
2136 // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2137 // - finally we're going to save that file, aren't we?
2138 // #105812# - 2002-12-02 - fs@openoffice.org
2139 m_aContent
.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST
);
2141 m_aContent
.enableDefaultInteractionHandler();
2143 // #53016# evtl. nur ein Filename ohne Pfad?
2144 String aFileNameOnly
;
2145 if( _aPath
.Len() && (_pImp
->_eMode
== FILEDLG_MODE_SAVE
)
2146 && (_aPath
.Search(':') == STRING_NOTFOUND
)
2147 && (_aPath
.Search('\\') == STRING_NOTFOUND
)
2148 && (_aPath
.Search('/') == STRING_NOTFOUND
))
2150 aFileNameOnly
= _aPath
;
2154 // kein Startpfad angegeben?
2155 if ( !_aPath
.Len() )
2157 // dann das Standard-Dir verwenden
2158 _aPath
= lcl_ensureFinalSlash( _pImp
->GetStandardDir() );
2160 // #53016# vorgegebener Dateiname an Pfad anh"angen
2161 if ( aFileNameOnly
.Len() )
2162 _aPath
+= aFileNameOnly
;
2165 //.....................................................................
2166 _aPath
= implGetInitialURL( _aPath
, GetStandardDir() );
2168 if ( _pImp
->_nStyle
& WB_SAVEAS
&& !m_bHasFilename
)
2169 // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2170 // - finally we're going to save that file, aren't we?
2171 m_aContent
.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST
);
2173 //.....................................................................
2174 // care for possible restrictions on the paths we're allowed to show
2175 if ( !m_aURLFilter
.isUrlAllowed( _aPath
) )
2176 _aPath
= m_aURLFilter
.getFilter()[0];
2178 // Ggf. Filter anzeigen.
2179 _pImp
->InitFilterList();
2181 // Initialen Filter einstellen.
2182 sal_uInt16 nFilterCount
= GetFilterCount();
2183 String
aAll( SvtResId( STR_FILTERNAME_ALL
) );
2184 sal_Bool bHasAll
= _pImp
->HasFilterListEntry( aAll
);
2185 if ( _pImp
->GetCurFilter() || nFilterCount
== 1 || ( nFilterCount
== 2 && bHasAll
) )
2187 // Ggf. einzigen Filter als aktuellen Filter setzen oder den einzigen
2188 // Filter, der nicht auf alle Dateien verweist.
2189 if ( !_pImp
->GetCurFilter() )
2191 sal_uInt16 nPos
= 0;
2192 if ( 2 == nFilterCount
&& bHasAll
)
2194 nPos
= nFilterCount
;
2197 if ( GetFilterName( nPos
) != aAll
)
2201 SvtFileDialogFilter_Impl
* pNewCurFilter
= _pImp
->_pFilter
->GetObject( nPos
);
2202 DBG_ASSERT( pNewCurFilter
, "SvtFileDialog::Execute: invalid filter pos!" );
2203 _pImp
->SetCurFilter( pNewCurFilter
, pNewCurFilter
->GetName() );
2206 // Anzeige anpassen.
2207 _pImp
->SelectFilterListEntry( _pImp
->GetCurFilter()->GetName() );
2208 SetDefaultExt( _pImp
->GetCurFilter()->GetExtension() );
2209 sal_uInt16 nSepPos
= GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP
);
2210 if ( nSepPos
!= STRING_NOTFOUND
)
2211 EraseDefaultExt( nSepPos
);
2215 // Ggf. Filter fuer alle Dateien setzen bzw. erzeugen.
2218 SvtFileDialogFilter_Impl
* pAllFilter
= implAddFilter( aAll
, UniString(RTL_CONSTASCII_USTRINGPARAM(FILEDIALOG_FILTER_ALL
)) );
2219 _pImp
->InsertFilterListEntry( pAllFilter
);
2220 _pImp
->SetCurFilter( pAllFilter
, aAll
);
2222 _pImp
->SelectFilterListEntry( aAll
);
2225 _pImp
->_pDefaultFilter
= _pImp
->GetCurFilter();
2228 // ggf. Filter isolieren.
2231 if ( !IsolateFilterFromPath_Impl( _aPath
, aFilter
) )
2234 sal_uInt16 nNewFilterFlags
= adjustFilter( aFilter
);
2235 if ( nNewFilterFlags
& ( FLT_NONEMPTY
| FLT_USERFILTER
) )
2237 _pImp
->_pEdFileName
->SetText( aFilter
);
2241 // Instanz fuer den gesetzten Pfad erzeugen und anzeigen.
2242 INetURLObject
aFolderURL( _aPath
);
2243 String
aFileName( aFolderURL
.getName( INetURLObject::LAST_SEGMENT
, false ) );
2244 xub_StrLen nFileNameLen
= aFileName
.Len();
2245 bool bFileToSelect
= nFileNameLen
!= 0;
2246 if ( bFileToSelect
&& aFileName
.GetChar( nFileNameLen
- 1 ) != INET_PATH_TOKEN
)
2248 _pImp
->_pEdFileName
->SetText( GET_DECODED_NAME( aFolderURL
) );
2249 aFolderURL
.removeSegment();
2252 INetURLObject aObj
= aFolderURL
;
2253 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
2255 // Ordner als aktuelles Verzeichnis setzen.
2256 aObj
.setFinalSlash();
2259 UpdateControls( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2261 // Somebody might want to enable some controls acording to the current filter
2264 // Zustand der Steuerelemente anpassen.
2265 // EndListeningAll();
2267 ViewHdl_Impl( this, NULL
);
2268 OpenURL_Impl( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2271 SvtDefModalDialogParent_Impl
aDefParent( this );
2273 // ggf. Gr"osse aus Ini lesen und setzen
2279 //-----------------------------------------------------------------------------
2280 void SvtFileDialog::implInitializeSpecialURLLists( )
2282 m_aURLFilter
= ::svt::RestrictedPaths();
2284 ::std::vector
< String
> aFavourites
;
2285 if ( m_aURLFilter
.hasFilter() )
2287 // if we have restrictions, then the "favourites" are the restricted folders only
2288 aFavourites
= m_aURLFilter
.getFilter();
2289 // for approved URLs, we needed the final slashes, for
2290 // favourites, we do not want to have them
2291 ::std::for_each( aFavourites
.begin(), aFavourites
.end(), RemoveFinalSlash() );
2295 ::rtl::OUString sFavouritesList
;
2296 if ( getEnvironmentValue( "PathFavourites", sFavouritesList
) )
2297 convertStringListToUrls( sFavouritesList
, aFavourites
, false );
2300 DBG_ASSERT( _pImp
->_pBtnStandard
, "SvtFileDialog::implInitializeSpecialURLLists: how this?" );
2301 if ( _pImp
->_pBtnStandard
)
2302 _pImp
->_pBtnStandard
->SetFavouriteLocations( aFavourites
);
2305 //-----------------------------------------------------------------------------
2306 void SvtFileDialog::executeAsync( ::svt::AsyncPickerAction::Action _eAction
,
2307 const String
& _rURL
, const String
& _rFilter
)
2309 DBG_ASSERT( !m_pCurrentAsyncAction
.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );
2311 m_pCurrentAsyncAction
= new AsyncPickerAction( this, _pFileView
, _eAction
);
2313 bool bReallyAsync
= true;
2314 m_aConfiguration
.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillAsynchronously" ) ) ) >>= bReallyAsync
;
2316 sal_Int32 nMinTimeout
= 0;
2317 m_aConfiguration
.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Timeout/Min" ) ) ) >>= nMinTimeout
;
2318 sal_Int32 nMaxTimeout
= 0;
2319 m_aConfiguration
.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Timeout/Max" ) ) ) >>= nMaxTimeout
;
2321 m_bInExecuteAsync
= true;
2322 m_pCurrentAsyncAction
->execute( _rURL
, _rFilter
, bReallyAsync
? nMinTimeout
: -1, nMaxTimeout
, GetBlackList() );
2323 m_bInExecuteAsync
= false;
2326 //*****************************************************************************
2328 void SvtFileDialog::FileSelect()
2330 if ( _pFileNotifier
)
2331 _pFileNotifier
->notify( FILE_SELECTION_CHANGED
, 0 );
2334 //*****************************************************************************
2336 void SvtFileDialog::FilterSelect()
2338 if ( _pFileNotifier
)
2339 _pFileNotifier
->notify( CTRL_STATE_CHANGED
,
2343 //*****************************************************************************
2345 void SvtFileDialog::SetStandardDir( const String
& rStdDir
)
2349 Die Methode setzt den Pfad f"ur den Standardknopf.
2353 INetURLObject
aObj( rStdDir
);
2354 DBG_ASSERT( aObj
.GetProtocol() != INET_PROT_NOT_VALID
, "Invalid protocol!" );
2355 aObj
.setFinalSlash();
2356 _pImp
->SetStandardDir( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2359 void SvtFileDialog::SetBlackList( const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& rBlackList
)
2361 _pImp
->SetBlackList( rBlackList
);
2364 //*****************************************************************************
2366 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& SvtFileDialog::GetBlackList() const
2368 return _pImp
->GetBlackList();
2370 //*****************************************************************************
2372 const String
& SvtFileDialog::GetStandardDir() const
2376 Diese Methode gibt den eingestellten Standardpfad zur"uck.
2380 return _pImp
->GetStandardDir();
2383 //*****************************************************************************
2385 void SvtFileDialog::PrevLevel_Impl()
2387 _pFileView
->EndInplaceEditing( false );
2390 executeAsync( AsyncPickerAction::ePrevLevel
, sDummy
, sDummy
);
2393 //*****************************************************************************
2395 void SvtFileDialog::OpenURL_Impl( const String
& _rURL
)
2397 _pFileView
->EndInplaceEditing( false );
2399 DBG_ASSERT( m_aURLFilter
.isUrlAllowed( _rURL
), "SvtFileDialog::OpenURL_Impl: forbidden URL! Should have been handled by the caller!" );
2400 executeAsync( AsyncPickerAction::eOpenURL
, _rURL
, getMostCurrentFilter( _pImp
) );
2403 //*****************************************************************************
2404 SvtFileDialogFilter_Impl
* SvtFileDialog::implAddFilter( const String
& _rFilter
, const String
& _rType
)
2406 SvtFileDialogFilter_Impl
* pNewFilter
= new SvtFileDialogFilter_Impl( _rFilter
, _rType
);
2407 _pImp
->_pFilter
->C40_INSERT( SvtFileDialogFilter_Impl
, pNewFilter
, (sal_uInt16
)0 );
2409 if ( !_pImp
->GetCurFilter() )
2410 _pImp
->SetCurFilter( pNewFilter
, _rFilter
);
2415 //*****************************************************************************
2417 void SvtFileDialog::AddFilter( const String
& _rFilter
, const String
& _rType
)
2419 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2420 implAddFilter ( _rFilter
, _rType
);
2423 //*****************************************************************************
2424 void SvtFileDialog::AddFilterGroup( const String
& _rFilter
, const Sequence
< StringPair
>& _rFilters
)
2426 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2428 implAddFilter( _rFilter
, String() );
2429 const StringPair
* pSubFilters
= _rFilters
.getConstArray();
2430 const StringPair
* pSubFiltersEnd
= pSubFilters
+ _rFilters
.getLength();
2431 for ( ; pSubFilters
!= pSubFiltersEnd
; ++pSubFilters
)
2432 implAddFilter( pSubFilters
->First
, pSubFilters
->Second
);
2435 //*****************************************************************************
2437 //-----------------------------------------------------------------------------
2438 void SvtFileDialog::SetCurFilter( const String
& rFilter
)
2440 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::SetCurFilter: currently executing!" );
2442 // Entsprechenden Filter suchen.
2443 sal_uInt16 nPos
= _pImp
->_pFilter
->Count();
2447 SvtFileDialogFilter_Impl
* pFilter
= _pImp
->_pFilter
->GetObject( nPos
);
2448 if ( pFilter
->GetName() == rFilter
)
2450 _pImp
->SetCurFilter( pFilter
, rFilter
);
2456 //*****************************************************************************
2458 String
SvtFileDialog::GetCurFilter() const
2462 const SvtFileDialogFilter_Impl
* pCurrentFilter
= _pImp
->GetCurFilter();
2463 if ( pCurrentFilter
)
2464 aFilter
= pCurrentFilter
->GetName();
2469 String
SvtFileDialog::getCurFilter( ) const
2471 return GetCurFilter();
2474 //*****************************************************************************
2476 sal_uInt16
SvtFileDialog::GetFilterCount() const
2478 return _pImp
->_pFilter
->Count();
2481 //*****************************************************************************
2483 const String
& SvtFileDialog::GetFilterName( sal_uInt16 nPos
) const
2485 DBG_ASSERT( nPos
< GetFilterCount(), "invalid index" );
2486 return _pImp
->_pFilter
->GetObject( nPos
)->GetName();
2489 //*****************************************************************************
2491 void SvtFileDialog::InitSize()
2493 if ( ! _pImp
->_aIniKey
.Len() )
2496 Size aDlgSize
= GetResizeOutputSizePixel();
2497 SetMinOutputSizePixel( aDlgSize
);
2499 if ( !_pImp
->_nFixDeltaHeight
)
2501 // Fixgr"ossen errechnen und merken
2502 Point aPnt
= _pFileView
->GetPosPixel();
2503 long nBoxH
= _pFileView
->GetSizePixel().Height();
2504 long nH
= GetSizePixel().Height();
2505 _pImp
->_nFixDeltaHeight
= nH
- nBoxH
;
2508 // initialize from config
2509 SvtViewOptions
aDlgOpt( E_DIALOG
, _pImp
->_aIniKey
);
2511 if ( aDlgOpt
.Exists() )
2513 SetWindowState( ByteString( String( aDlgOpt
.GetWindowState() ), osl_getThreadTextEncoding() ) );
2515 Any aUserData
= aDlgOpt
.GetUserItem( ::rtl::OUString::createFromAscii( "UserData" ) );
2516 ::rtl::OUString sCfgStr
;
2517 if ( aUserData
>>= sCfgStr
)
2518 _pFileView
->SetConfigString( String( sCfgStr
) );
2522 //*****************************************************************************
2524 SvStringsDtor
* SvtFileDialog::GetPathList() const
2526 SvStringsDtor
* pList
= new SvStringsDtor
;
2527 sal_uLong nCount
= _pFileView
->GetSelectionCount();
2528 SvLBoxEntry
* pEntry
= nCount
? _pFileView
->FirstSelected() : NULL
;
2534 if ( _pImp
->_pEdFileName
->GetText().Len() && _bIsInExecute
)
2535 pURL
= new String( _pImp
->_pEdFileName
->GetURL() );
2537 pURL
= new String( _aPath
);
2539 pList
->Insert( pURL
, pList
->Count() );
2545 String
* pURL
= new String( _pFileView
->GetURL( pEntry
) );
2546 pList
->Insert( pURL
, pList
->Count() );
2547 pEntry
= _pFileView
->NextSelected( pEntry
);
2554 //*****************************************************************************
2556 void SvtFileDialog::implArrangeControls()
2558 // this is the list of controls in the order they should be tabbed
2559 // from topleft to bottomright
2560 // pb: #136070# new order so all LabeledBy relations are correct now
2561 Control
* pControls
[] =
2563 _pImp
->_pFtCurrentPath
,
2564 _pImp
->_pBtnUp
, _pImp
->_pBtnNewFolder
, _pImp
->_pBtnStandard
, // image buttons
2565 _pFileView
, // the file view
2566 _pImp
->_pFtFileName
, _pImp
->_pEdFileName
,
2567 _pImp
->_pFtFileVersion
, _pImp
->_pLbFileVersion
,
2568 _pImp
->_pFtTemplates
, _pImp
->_pLbTemplates
,
2569 _pImp
->_pFtImageTemplates
, _pImp
->_pLbImageTemplates
,
2570 _pImp
->_pFtFileType
, _pImp
->GetFilterListControl(), // edit fields/list boxes
2571 _pImp
->_pCbPassword
, _pImp
->_pCbAutoExtension
, _pImp
->_pCbOptions
, // checkboxes
2572 _pCbReadOnly
, _pCbLinkBox
, _pCbPreviewBox
, _pCbSelection
, _pPbPlay
, // check boxes (continued)
2573 _pImp
->_pBtnFileOpen
, _pImp
->_pBtnCancel
, _pImp
->_pBtnHelp
// buttons
2575 // (including the FixedTexts is important - not for tabbing order (they're irrelevant there),
2576 // but for working keyboard shortcuts)
2577 // 96861 - 23.01.2002 - fs@openoffice.org
2580 // loop through all these controls and adjust the z-order
2581 Window
* pPreviousWin
= NULL
;
2582 Control
** pCurrent
= pControls
;
2583 for ( sal_Int32 i
= 0; i
< sal_Int32(sizeof( pControls
) / sizeof( pControls
[ 0 ] )); ++i
, ++pCurrent
)
2586 // this control is not available in the current operation mode -> skip
2590 (*pCurrent
)->SetZOrder( pPreviousWin
, WINDOW_ZORDER_BEHIND
);
2592 (*pCurrent
)->SetZOrder( NULL
, WINDOW_ZORDER_FIRST
);
2594 pPreviousWin
= *pCurrent
;
2597 // FileName edit not the first control but it should have the focus initially
2598 _pImp
->_pEdFileName
->GrabFocus();
2601 //*****************************************************************************
2603 sal_Bool
SvtFileDialog::IsolateFilterFromPath_Impl( String
& rPath
, String
& rFilter
)
2606 String
aReversePath( rPath
);
2607 aReversePath
.Reverse();
2608 sal_uInt16 nQuestionMarkPos
= rPath
.Search( '?' );
2610 if ( nQuestionMarkPos
!= STRING_NOTFOUND
)
2612 // Fragezeichen als Wildcard nur bei Files
2613 INetProtocol eProt
= INetURLObject::CompareProtocolScheme( rPath
);
2615 if ( INET_PROT_NOT_VALID
!= eProt
&& INET_PROT_FILE
!= eProt
)
2616 nQuestionMarkPos
= STRING_NOTFOUND
;
2618 sal_uInt16 nWildCardPos
= Min( rPath
.Search( FILEDIALOG_DEF_WILDCARD
), nQuestionMarkPos
);
2621 if ( nWildCardPos
!= STRING_NOTFOUND
)
2623 sal_uInt16 nPathTokenPos
= aReversePath
.Search( INET_PATH_TOKEN
);
2625 if ( nPathTokenPos
== STRING_NOTFOUND
)
2628 #if defined(WNT) || defined(OS2)
2635 nPathTokenPos
= aReversePath
.Search( aDelim
);
2637 if ( nPathTokenPos
== STRING_NOTFOUND
)
2639 nPathTokenPos
= aReversePath
.Search( '/' );
2643 if ( nPathTokenPos
== STRING_NOTFOUND
)
2645 nPathTokenPos
= aReversePath
.Search( ':' );
2651 if ( nPathTokenPos
!= STRING_NOTFOUND
)
2653 if ( nPathTokenPos
< (rPath
.Len() - nWildCardPos
- 1) )
2655 ErrorHandler::HandleError( ERRCODE_SFX_INVALIDSYNTAX
);
2659 // Filter abschneiden.
2660 rFilter
= aReversePath
;
2661 rFilter
.Erase( nPathTokenPos
);
2664 // Ordner bestimmen.
2665 rPath
= aReversePath
;
2666 rPath
.Erase( 0, nPathTokenPos
);
2679 //*****************************************************************************
2681 //-----------------------------------------------------------------------------
2682 void SvtFileDialog::implUpdateImages( )
2684 // determine high contrast mode
2686 sal_Bool bIsHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
2687 m_aImages
= ImageList( SvtResId( bIsHighContrast
? RID_FILEPICKER_IMAGES_HC
: RID_FILEPICKER_IMAGES
) );
2690 // set the appropriate images on the buttons
2691 if ( _pImp
->_pBtnUp
)
2692 _pImp
->_pBtnUp
->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_UP
) );
2694 if ( _pImp
->_pBtnStandard
)
2695 _pImp
->_pBtnStandard
->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_STD
) );
2697 if ( _pImp
->_pBtnNewFolder
)
2698 _pImp
->_pBtnNewFolder
->SetModeImage( GetButtonImage( IMG_FILEDLG_CREATEFOLDER
) );
2701 //-----------------------------------------------------------------------------
2702 void SvtFileDialog::DataChanged( const DataChangedEvent
& _rDCEvt
)
2704 if ( DATACHANGED_SETTINGS
== _rDCEvt
.GetType() )
2705 implUpdateImages( );
2707 ModalDialog::DataChanged( _rDCEvt
);
2710 //-----------------------------------------------------------------------------
2711 void SvtFileDialog::Resize()
2716 Size aDlgSize
= GetResizeOutputSizePixel();
2717 Size aOldSize
= _pImp
->_aDlgSize
;
2718 _pImp
->_aDlgSize
= aDlgSize
;
2719 long nWinDeltaW
= 0;
2722 _pPrevWin
->GetPosPixel().X() > _pFileView
->GetPosPixel().X() )
2724 nWinDeltaW
= _pPrevWin
->GetOutputSizePixel().Width() + _pImp
->_a6Size
.Width();
2727 Size aNewSize
= _pFileView
->GetSizePixel();
2728 Point
aBoxPos( _pFileView
->GetPosPixel() );
2729 long nDeltaY
= aNewSize
.Height();
2730 long nDeltaX
= aNewSize
.Width();
2731 aNewSize
.Height() = aDlgSize
.Height() - _pImp
->_nFixDeltaHeight
;
2732 aNewSize
.Width() = aDlgSize
.Width() - aBoxPos
.X() - _pImp
->_a6Size
.Width() - nWinDeltaW
;
2733 if ( aOldSize
.Height() )
2734 nDeltaY
= _pImp
->_aDlgSize
.Height() - aOldSize
.Height();
2736 nDeltaY
= aNewSize
.Height() - nDeltaY
;
2737 nDeltaX
= aNewSize
.Width() - nDeltaX
;
2740 nWinDeltaW
= nDeltaX
* 2 / 3;
2741 aNewSize
.Width() -= nWinDeltaW
;
2742 nDeltaX
-= nWinDeltaW
;
2744 _pFileView
->SetSizePixel( aNewSize
);
2746 if ( !nDeltaY
&& !nDeltaX
)
2747 // Dieses Resize wurde nur zum Ein - oder Ausblenden des Indicators aufgerufen
2753 // controls to move vertically
2755 Control
* aMoveControlsVert
[] =
2757 _pImp
->_pFtFileName
, _pImp
->_pEdFileName
, _pImp
->_pFtFileVersion
, _pImp
->_pLbFileVersion
,
2758 _pImp
->_pFtTemplates
, _pImp
->_pLbTemplates
, _pImp
->_pFtImageTemplates
, _pImp
->_pLbImageTemplates
,
2759 _pImp
->_pFtFileType
, _pImp
->GetFilterListControl(), _pCbReadOnly
, _pCbLinkBox
, _pCbPreviewBox
,
2760 _pPbPlay
, _pImp
->_pCbPassword
, _pImp
->_pCbAutoExtension
, _pImp
->_pCbOptions
, _pCbSelection
2762 Control
** ppMoveControls
= aMoveControlsVert
;
2763 Control
** ppMoveControlsEnd
= ppMoveControls
+ sizeof( aMoveControlsVert
) / sizeof( aMoveControlsVert
[0] );
2764 for ( ; ppMoveControls
!= ppMoveControlsEnd
; ++ppMoveControls
)
2765 lcl_MoveControl( *ppMoveControls
, 0, nDeltaY
);
2768 // controls to move vertically and horizontally
2770 Control
* aMoveControlsBoth
[] =
2772 _pImp
->_pBtnFileOpen
, _pImp
->_pBtnCancel
, _pImp
->_pBtnHelp
2774 Control
** ppMoveControls
= aMoveControlsBoth
;
2775 Control
** ppMoveControlsEnd
= ppMoveControls
+ sizeof( aMoveControlsBoth
) / sizeof( aMoveControlsBoth
[0] );
2776 for ( ; ppMoveControls
!= ppMoveControlsEnd
; ++ppMoveControls
)
2777 lcl_MoveControl( *ppMoveControls
, nDeltaX
, nDeltaY
);
2780 // controls to move horizontally
2782 Control
* aMoveControlsHor
[] =
2784 _pImp
->_pBtnUp
, _pImp
->_pBtnNewFolder
, _pImp
->_pBtnStandard
2786 Control
** ppMoveControls
= aMoveControlsHor
;
2787 Control
** ppMoveControlsEnd
= ppMoveControls
+ sizeof( aMoveControlsHor
) / sizeof( aMoveControlsHor
[0] );
2788 for ( ; ppMoveControls
!= ppMoveControlsEnd
; ++ppMoveControls
)
2789 lcl_MoveControl( *ppMoveControls
, nDeltaX
, 0 );
2795 Control
* aSizeControls
[] =
2797 _pImp
->_pEdFileName
, _pImp
->_pLbFileVersion
, _pImp
->_pLbTemplates
, _pImp
->_pLbImageTemplates
,
2798 _pImp
->GetFilterListControl(), _pImp
->_pFtCurrentPath
,
2800 sal_Int32 nSizeControls
= sizeof( aSizeControls
) / sizeof( aSizeControls
[0] );
2801 Control
** ppSizeControls
= aSizeControls
;
2802 for ( sal_Int32 j
=0; j
<nSizeControls
; ++j
, ++ppSizeControls
)
2804 if ( *ppSizeControls
)
2806 aNewSize
= (*ppSizeControls
)->GetSizePixel();
2807 aNewSize
.Width() += nDeltaX
;
2808 (*ppSizeControls
)->SetSizePixel( aNewSize
);
2813 // zus"atzliche Controls ausrichten
2815 _pPrevWin
->GetPosPixel().X() > _pFileView
->GetPosPixel().X() )
2817 // Controls vom Typ Window speziell ausrichten
2818 // auch die Gr"osse anpassen
2819 Point aNewPos
= _pPrevWin
->GetPosPixel();
2820 aNewPos
.X() += nDeltaX
;
2821 _pPrevWin
->SetPosPixel( aNewPos
);
2822 _pPrevBmp
->SetPosPixel( aNewPos
);
2823 aNewSize
= _pPrevWin
->GetOutputSizePixel();
2824 aNewSize
.Width() += nWinDeltaW
;
2825 aNewSize
.Height() += nDeltaY
;
2826 if ( !aOldSize
.Height() )
2827 aNewSize
.Height() -= ( _pImp
->_a6Size
.Height() / 2 );
2828 _pPrevWin
->SetOutputSizePixel( aNewSize
);
2829 _pPrevBmp
->SetOutputSizePixel( aNewSize
);
2830 _pPrevBmp
->Invalidate();
2833 if ( _pFileNotifier
)
2834 _pFileNotifier
->notify( DIALOG_SIZE_CHANGED
, 0 );
2837 //*****************************************************************************
2839 //-----------------------------------------------------------------------------
2840 Control
* SvtFileDialog::getControl( sal_Int16 _nControlId
, sal_Bool _bLabelControl
) const
2842 Control
* pReturn
= NULL
;
2844 switch ( _nControlId
)
2846 case CONTROL_FILEVIEW
:
2847 pReturn
= _bLabelControl
? NULL
: static_cast< Control
* >( _pFileView
);
2851 pReturn
= _bLabelControl
2852 ? static_cast< Control
* >( _pImp
->_pFtFileName
)
2853 : static_cast< Control
* >( _pImp
->_pEdFileName
);
2856 case EDIT_FILEURL_LABEL
:
2857 pReturn
= static_cast< Control
* >( _pImp
->_pFtFileName
);
2860 case CHECKBOX_AUTOEXTENSION
:
2861 pReturn
= _pImp
->_pCbAutoExtension
;
2864 case CHECKBOX_PASSWORD
:
2865 pReturn
= _pImp
->_pCbPassword
;
2868 case CHECKBOX_FILTEROPTIONS
:
2869 pReturn
= _pImp
->_pCbOptions
;
2872 case CHECKBOX_READONLY
:
2873 pReturn
= _pCbReadOnly
;
2877 pReturn
= _pCbLinkBox
;
2880 case CHECKBOX_PREVIEW
:
2881 pReturn
= _pCbPreviewBox
;
2884 case CHECKBOX_SELECTION
:
2885 pReturn
= _pCbSelection
;
2888 case LISTBOX_FILTER
:
2889 pReturn
= _bLabelControl
? _pImp
->_pFtFileType
: _pImp
->GetFilterListControl();
2892 case LISTBOX_FILTER_LABEL
:
2893 pReturn
= _pImp
->_pFtFileType
;
2896 case FIXEDTEXT_CURRENTFOLDER
:
2897 pReturn
= _pImp
->_pFtCurrentPath
;
2900 case LISTBOX_VERSION
:
2901 pReturn
= _bLabelControl
2902 ? static_cast< Control
* >( _pImp
->_pFtFileVersion
)
2903 : static_cast< Control
* >( _pImp
->_pLbFileVersion
);
2906 case LISTBOX_TEMPLATE
:
2907 pReturn
= _bLabelControl
2908 ? static_cast< Control
* >( _pImp
->_pFtTemplates
)
2909 : static_cast< Control
* >( _pImp
->_pLbTemplates
);
2912 case LISTBOX_IMAGE_TEMPLATE
:
2913 pReturn
= _bLabelControl
2914 ? static_cast< Control
* >( _pImp
->_pFtImageTemplates
)
2915 : static_cast< Control
* >( _pImp
->_pLbImageTemplates
);
2918 case LISTBOX_VERSION_LABEL
:
2919 pReturn
= _pImp
->_pFtFileVersion
;
2922 case LISTBOX_TEMPLATE_LABEL
:
2923 pReturn
= _pImp
->_pFtTemplates
;
2926 case LISTBOX_IMAGE_TEMPLATE_LABEL
:
2927 pReturn
= _pImp
->_pFtImageTemplates
;
2931 pReturn
= _pImp
->_pBtnFileOpen
;
2934 case PUSHBUTTON_CANCEL
:
2935 pReturn
= _pImp
->_pBtnCancel
;
2938 case PUSHBUTTON_PLAY
:
2942 case PUSHBUTTON_HELP
:
2943 pReturn
= _pImp
->_pBtnHelp
;
2946 case TOOLBOXBUTOON_DEFAULT_LOCATION
:
2947 pReturn
= _pImp
->_pBtnStandard
;
2950 case TOOLBOXBUTOON_LEVEL_UP
:
2951 pReturn
= _pImp
->_pBtnUp
;
2954 case TOOLBOXBUTOON_NEW_FOLDER
:
2955 pReturn
= _pImp
->_pBtnNewFolder
;
2958 case LISTBOX_FILTER_SELECTOR
:
2959 // only exists on SalGtkFilePicker
2963 DBG_ERRORFILE( "SvtFileDialog::getControl: invalid id!" );
2968 // -----------------------------------------------------------------------
2969 void SvtFileDialog::enableControl( sal_Int16 _nControlId
, sal_Bool _bEnable
)
2971 Control
* pControl
= getControl( _nControlId
, sal_False
);
2973 EnableControl( pControl
, _bEnable
);
2974 Control
* pLabel
= getControl( _nControlId
, sal_True
);
2976 EnableControl( pLabel
, _bEnable
);
2979 // -----------------------------------------------------------------------
2980 void SvtFileDialog::AddControls_Impl( )
2982 // create the "insert as link" checkbox, if needed
2983 if ( _nExtraBits
& SFX_EXTRA_INSERTASLINK
)
2985 _pCbLinkBox
= new CheckBox( this );
2986 _pCbLinkBox
->SetText( SvtResId( STR_SVT_FILEPICKER_INSERT_AS_LINK
) );
2987 _pCbLinkBox
->SetHelpId( HID_FILEDLG_LINK_CB
);
2988 AddControl( _pCbLinkBox
);
2989 ReleaseOwnerShip( _pCbLinkBox
);
2990 _pCbLinkBox
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
2993 // create the "show preview" checkbox ( and the preview window, too ), if needed
2994 if ( _nExtraBits
& SFX_EXTRA_SHOWPREVIEW
)
2996 _pImp
->_aIniKey
= IMPGRF_CONFIGNAME
;
2997 // because the "<All Formats> (*.bmp,*...)" entry is to wide,
2998 // we need to disable the auto width feature of the filter box
2999 _pImp
->DisableFilterBoxAutoWidth();
3002 _pCbPreviewBox
= new CheckBox( this );
3003 _pCbPreviewBox
->SetText( SvtResId( STR_SVT_FILEPICKER_SHOW_PREVIEW
) );
3004 _pCbPreviewBox
->SetHelpId( HID_FILEDLG_PREVIEW_CB
);
3005 AddControl( _pCbPreviewBox
);
3006 ReleaseOwnerShip( _pCbPreviewBox
);
3007 _pCbPreviewBox
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
3009 // Preview-Fenster erst hier erzeugen
3010 _pPrevWin
= new Window( this, WinBits( WB_BORDER
) );
3011 AddControl( _pPrevWin
);
3012 ReleaseOwnerShip( _pPrevWin
);
3015 _pPrevBmp
= new FixedBitmap( this, WinBits( WB_BORDER
) );
3016 _pPrevBmp
->SetBackground( Wallpaper( Color( COL_WHITE
) ) );
3018 _pPrevBmp
->SetAccessibleName(SvtResId(STR_PREVIEW
));
3021 if ( _nExtraBits
& SFX_EXTRA_AUTOEXTENSION
)
3023 _pImp
->_pCbAutoExtension
= new CheckBox( this, SvtResId( CB_AUTO_EXTENSION
) );
3024 _pImp
->_pCbAutoExtension
->SetText( SvtResId( STR_SVT_FILEPICKER_AUTO_EXTENSION
) );
3025 _pImp
->_pCbAutoExtension
->Check( sal_True
);
3026 AddControl( _pImp
->_pCbAutoExtension
);
3027 ReleaseOwnerShip( _pImp
->_pCbAutoExtension
);
3028 _pImp
->_pCbAutoExtension
->SetClickHdl( LINK( this, SvtFileDialog
, AutoExtensionHdl_Impl
) );
3031 if ( _nExtraBits
& SFX_EXTRA_FILTEROPTIONS
)
3033 _pImp
->_pCbOptions
= new CheckBox( this, SvtResId( CB_OPTIONS
) );
3034 _pImp
->_pCbOptions
->SetText( SvtResId( STR_SVT_FILEPICKER_FILTER_OPTIONS
) );
3035 AddControl( _pImp
->_pCbOptions
);
3036 ReleaseOwnerShip( _pImp
->_pCbOptions
);
3037 _pImp
->_pCbOptions
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
3040 if ( _nExtraBits
& SFX_EXTRA_SELECTION
)
3042 _pCbSelection
= new CheckBox( this, SvtResId( CB_OPTIONS
) );
3043 _pCbSelection
->SetText( SvtResId( STR_SVT_FILEPICKER_SELECTION
) );
3044 AddControl( _pCbSelection
);
3045 ReleaseOwnerShip( _pCbSelection
);
3046 _pCbSelection
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
3049 if ( _nExtraBits
& SFX_EXTRA_PLAYBUTTON
)
3051 _pPbPlay
= new PushButton( this );
3052 _pPbPlay
->SetText( SvtResId( STR_SVT_FILEPICKER_PLAY
) );
3053 _pPbPlay
->SetHelpId( HID_FILESAVE_DOPLAY
);
3054 AddControl( _pPbPlay
);
3055 ReleaseOwnerShip( _pPbPlay
);
3056 _pPbPlay
->SetClickHdl( LINK( this, SvtFileDialog
, PlayButtonHdl_Impl
) );
3059 if ( _nExtraBits
& SFX_EXTRA_SHOWVERSIONS
)
3061 _pImp
->_pFtFileVersion
= new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
3062 _pImp
->_pFtFileVersion
->SetText( SvtResId( STR_SVT_FILEPICKER_VERSION
) );
3064 _pImp
->_pLbFileVersion
= new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
3065 _pImp
->_pLbFileVersion
->SetHelpId( HID_FILEOPEN_VERSION
);
3067 else if ( _nExtraBits
& SFX_EXTRA_TEMPLATES
)
3069 _pImp
->_pFtTemplates
= new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
3070 _pImp
->_pFtTemplates
->SetText( SvtResId( STR_SVT_FILEPICKER_TEMPLATES
) );
3072 _pImp
->_pLbTemplates
= new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
3073 _pImp
->_pLbTemplates
->SetHelpId( HID_FILEOPEN_VERSION
);
3074 // This is strange. During the re-factoring during 96930, I discovered that this help id
3075 // is set in the "Templates mode". This was hidden in the previous implementation.
3076 // Shouldn't this be a more meaningfull help id.
3077 // 96930 - 15.08.2002 - fs@openoffice.org
3079 else if ( _nExtraBits
& SFX_EXTRA_IMAGE_TEMPLATE
)
3081 _pImp
->_pFtImageTemplates
= new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
3082 _pImp
->_pFtImageTemplates
->SetText( SvtResId( STR_SVT_FILEPICKER_IMAGE_TEMPLATE
) );
3084 _pImp
->_pLbImageTemplates
= new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
3085 _pImp
->_pLbImageTemplates
->SetHelpId( HID_FILEOPEN_IMAGE_TEMPLATE
);
3089 // -----------------------------------------------------------------------
3090 sal_Int32
SvtFileDialog::getTargetColorDepth()
3093 return _pPrevBmp
->GetBitCount();
3098 // -----------------------------------------------------------------------
3099 sal_Int32
SvtFileDialog::getAvailableWidth()
3102 return _pPrevBmp
->GetOutputSizePixel().Width();
3107 // -----------------------------------------------------------------------
3108 sal_Int32
SvtFileDialog::getAvailableHeight()
3111 return _pPrevBmp
->GetOutputSizePixel().Height();
3116 // -----------------------------------------------------------------------
3117 void SvtFileDialog::setImage( sal_Int16
/*aImageFormat*/, const Any
& rImage
)
3119 if ( ! _pPrevBmp
|| ! _pPrevBmp
->IsVisible() )
3122 Sequence
< sal_Int8
> aBmpSequence
;
3124 if ( rImage
>>= aBmpSequence
)
3127 SvMemoryStream
aData( aBmpSequence
.getArray(),
3128 aBmpSequence
.getLength(),
3132 _pPrevBmp
->SetBitmap( aBmp
);
3137 _pPrevBmp
->SetBitmap( aEmpty
);
3141 // -----------------------------------------------------------------------
3142 sal_Bool
SvtFileDialog::setShowState( sal_Bool
/*bShowState*/ )
3144 // #97633 for the system filedialog it's
3145 // usefull to make the preview switchable
3146 // because the preview occupies
3147 // half of the size of the file listbox
3148 // which is not the case here,
3149 // so we (TRA/FS) decided not to make
3150 // the preview window switchable because
3151 // else we would have to change the layout
3152 // of the file dialog dynamically
3153 // support for set/getShowState is opionally
3154 // see com::sun::star::ui::dialogs::XFilePreview
3158 _pPrevBmp->Show( bShowState );
3168 // -----------------------------------------------------------------------
3169 String
SvtFileDialog::getCurrentFileText( ) const
3172 if ( _pImp
&& _pImp
->_pEdFileName
)
3173 sReturn
= _pImp
->_pEdFileName
->GetText();
3177 // -----------------------------------------------------------------------
3178 void SvtFileDialog::setCurrentFileText( const String
& _rText
, bool _bSelectAll
)
3180 if ( _pImp
&& _pImp
->_pEdFileName
)
3182 _pImp
->_pEdFileName
->SetText( _rText
);
3184 _pImp
->_pEdFileName
->SetSelection( Selection( 0, _rText
.Len() ) );
3188 // -----------------------------------------------------------------------
3189 sal_Bool
SvtFileDialog::isAutoExtensionEnabled()
3191 return _pImp
->_pCbAutoExtension
&& _pImp
->_pCbAutoExtension
->IsChecked();
3194 // -----------------------------------------------------------------------
3195 sal_Bool
SvtFileDialog::getShowState()
3198 return _pPrevBmp
->IsVisible();
3203 // -----------------------------------------------------------------------
3204 void SvtFileDialog::ReleaseOwnerShip( Window
* pUserControl
)
3208 Die Methode sorgt dafuer das das spezifizierte Element nicht mehr im Besitz
3213 ControlChain_Impl
* pElement
= _pUserControls
;
3216 if ( pElement
->_pControl
== pUserControl
)
3218 pElement
->_bHasOwnerShip
= sal_False
;
3221 pElement
= pElement
->_pNext
;
3225 //***************************************************************************
3227 sal_Bool
SvtFileDialog::AddControl( Window
* pControl
, sal_Bool bNewLine
)
3229 // control already exists
3230 ControlChain_Impl
* pElement
= _pUserControls
;
3233 if ( pElement
->_pControl
== pControl
)
3235 pElement
= pElement
->_pNext
;
3238 // Check if controls have already been added.
3239 Size
aNewControlSize( pControl
->GetOutputSizePixel() );
3240 Size
aDlgSize( GetOutputSizePixel() );
3241 WindowType nType
= pControl
->GetType();
3242 if ( !aNewControlSize
.Height() )
3245 Size
aSize( 0, 10 );
3246 if ( nType
== WINDOW_PUSHBUTTON
)
3248 Size aDefSiz
= LogicToPixel( Size( 50, 14 ), MAP_APPFONT
);
3249 long nTextWidth
= pControl
->GetTextWidth( pControl
->GetText() );
3250 aSize
.Width() = nTextWidth
+ WIDTH_ADDITION
;
3252 // PushButton: Mindestbreite 50 logische Einheiten,
3253 // H"ohe immer 14 logische Einheiten
3254 if ( aDefSiz
.Width() > aSize
.Width() )
3255 aSize
.Width() = aDefSiz
.Width();
3256 aSize
.Height() = aDefSiz
.Height();
3257 aNewControlSize
= aSize
;
3260 aNewControlSize
= LogicToPixel( aSize
, MAP_APPFONT
);
3261 if ( nType
!= WINDOW_PUSHBUTTON
)
3262 aNewControlSize
.Width() = pControl
->GetTextWidth( pControl
->GetText() ) + WIDTH_ADDITION
;
3263 if ( nType
== WINDOW_CHECKBOX
)
3264 aNewControlSize
.Width() += WIDTH_ADDITION
;
3265 if ( nType
== WINDOW_WINDOW
)
3267 aNewControlSize
.Height() = GetOutputSizePixel().Height() - 18;
3268 aNewControlSize
.Width() = 200;
3269 aDlgSize
.Width() += 210;
3270 SetOutputSizePixel( aDlgSize
);
3272 pControl
->SetOutputSizePixel( aNewControlSize
);
3274 Point aNewControlPos
;
3275 Size
* pNewDlgSize
= NULL
;
3276 sal_Bool bNewRow
= bNewLine
;
3277 sal_Bool bFirstNewRow
= sal_False
;
3279 if ( nType
== WINDOW_WINDOW
)
3281 aNewControlPos
.X() = aDlgSize
.Width() - 210;
3282 aNewControlPos
.Y() = 8;
3284 else if ( _pUserControls
)
3286 Point
aNewControlRange( _pUserControls
->_pControl
->GetPosPixel() );
3287 long nPrevControlHeight
= _pUserControls
->_pControl
->GetSizePixel().Height();
3289 Point( _pUserControls
->_pControl
->GetOutputSizePixel().Width(), 0 );
3290 aNewControlPos
= aNewControlRange
;
3291 if ( nPrevControlHeight
> aNewControlSize
.Height() )
3293 long nY
= nPrevControlHeight
;
3294 nY
-= aNewControlSize
.Height();
3296 aNewControlPos
.Y() += nY
;
3298 aNewControlPos
+= LogicToPixel( Point( 3, 0 ), MAP_APPFONT
);
3299 aNewControlRange
+= LogicToPixel( Point( 9, 0 ), MAP_APPFONT
);
3300 aNewControlRange
+= Point( aNewControlSize
.Width(), 0 );
3302 // Check if a new row has to be created.
3303 if ( aNewControlRange
.X() > aDlgSize
.Width() )
3308 // Create a new row if there was no usercontrol before.
3310 bFirstNewRow
= sal_True
;
3313 // Check if a new row has to be created.
3314 Size aBorderSize
= LogicToPixel( Size( 6, 6 ), MAP_APPFONT
);
3315 long nLeftBorder
= aBorderSize
.Width();
3316 long nLowerBorder
= aBorderSize
.Height();
3319 // Set control at the beginning of a new line.
3320 long nSmallBorderHeight
= nLowerBorder
/ 2;
3321 aNewControlPos
= Point( nLeftBorder
, 0 );
3322 aNewControlPos
+= Point( 0, aDlgSize
.Height() );
3323 aNewControlPos
.Y() -= nSmallBorderHeight
;
3325 pNewDlgSize
= new Size( aDlgSize
);
3326 pNewDlgSize
->Height() -= nSmallBorderHeight
;
3327 pNewDlgSize
->Height() += aNewControlSize
.Height();
3328 pNewDlgSize
->Height() += nLowerBorder
;
3332 // Check if the window has to be resized.
3333 Size
aNewControlRange( 0, aNewControlPos
.Y() );
3334 aNewControlRange
.Height() += aNewControlSize
.Height();
3335 aNewControlRange
.Height() += nLowerBorder
;
3336 if ( aNewControlRange
.Height() > aDlgSize
.Height() )
3337 pNewDlgSize
= new Size( aDlgSize
.Width(), aNewControlRange
.Height() );
3343 SetOutputSizePixel( *pNewDlgSize
);
3346 pControl
->SetPosPixel( aNewControlPos
);
3348 _pUserControls
= new ControlChain_Impl( pControl
, _pUserControls
);
3353 sal_Bool
SvtFileDialog::ContentHasParentFolder( const rtl::OUString
& rURL
)
3355 m_aContent
.bindTo( rURL
);
3357 if ( m_aContent
.isInvalid() )
3360 return m_aContent
.hasParentFolder( ) && m_aContent
.isValid();
3363 sal_Bool
SvtFileDialog::ContentCanMakeFolder( const rtl::OUString
& rURL
)
3365 m_aContent
.bindTo( rURL
);
3367 if ( m_aContent
.isInvalid() )
3370 return m_aContent
.canCreateFolder( ) && m_aContent
.isValid();
3373 sal_Bool
SvtFileDialog::ContentGetTitle( const rtl::OUString
& rURL
, String
& rTitle
)
3375 m_aContent
.bindTo( rURL
);
3377 if ( m_aContent
.isInvalid() )
3380 ::rtl::OUString sTitle
;
3381 m_aContent
.getTitle( sTitle
);
3384 return m_aContent
.isValid();
3387 void SvtFileDialog::appendDefaultExtension(String
& _rFileName
,
3388 const String
& _rFilterDefaultExtension
,
3389 const String
& _rFilterExtensions
)
3391 String
aTemp(_rFileName
);
3392 aTemp
.ToLowerAscii();
3393 String
aType(_rFilterExtensions
);
3394 aType
.ToLowerAscii();
3396 if ( ! aType
.EqualsAscii(FILEDIALOG_FILTER_ALL
) )
3398 sal_uInt16 nWildCard
= aType
.GetTokenCount( FILEDIALOG_DEF_EXTSEP
);
3399 sal_uInt16 nIndex
, nPos
= 0;
3401 for ( nIndex
= 0; nIndex
< nWildCard
; nIndex
++ )
3403 String
aExt(aType
.GetToken( 0, FILEDIALOG_DEF_EXTSEP
, nPos
));
3404 // take care of a leading *
3405 sal_uInt16 nExtOffset
= (aExt
.GetBuffer()[0] == '*' ? 1 : 0);
3406 sal_Unicode
* pExt
= aExt
.GetBufferAccess() + nExtOffset
;
3407 xub_StrLen nExtLen
= aExt
.Len() - nExtOffset
;
3408 xub_StrLen nOffset
= aTemp
.Len() - nExtLen
;
3409 // minimize search by starting at last possible index
3410 if ( aTemp
.Search(pExt
, nOffset
) == nOffset
)
3414 if ( nIndex
>= nWildCard
)
3417 _rFileName
+= _rFilterDefaultExtension
;
3422 // -----------------------------------------------------------------------
3424 // QueryFolderNameDialog -------------------------------------------------------
3428 QueryFolderNameDialog::QueryFolderNameDialog
3431 const String
& rTitle
,
3432 const String
& rDefaultText
,
3435 ModalDialog( _pParent
, SvtResId( DLG_SVT_QUERYFOLDERNAME
) ),
3437 aNameText ( this, SvtResId( FT_SVT_QUERYFOLDERNAME_DLG_NAME
) ),
3438 aNameEdit ( this, SvtResId( ED_SVT_QUERYFOLDERNAME_DLG_NAME
) ),
3439 aNameLine ( this, SvtResId( FL_SVT_QUERYFOLDERNAME_DLG_NAME
) ),
3440 aOKBtn ( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_OK
) ),
3441 aCancelBtn ( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_CANCEL
) )
3445 aNameEdit
.SetText( rDefaultText
);
3446 aNameEdit
.SetSelection( Selection( 0, rDefaultText
.Len() ) );
3447 aOKBtn
.SetClickHdl( LINK( this, QueryFolderNameDialog
, OKHdl
) );
3448 aNameEdit
.SetModifyHdl( LINK( this, QueryFolderNameDialog
, NameHdl
) );
3451 aNameLine
.SetText( *pGroupName
);
3454 // -----------------------------------------------------------------------
3455 IMPL_LINK( QueryFolderNameDialog
, OKHdl
, Button
*, EMPTYARG
)
3458 aNameEdit
.SetText( aNameEdit
.GetText().EraseLeadingChars().EraseTrailingChars() );
3459 EndDialog( RET_OK
);
3463 // -----------------------------------------------------------------------
3464 IMPL_LINK( QueryFolderNameDialog
, NameHdl
, Edit
*, EMPTYARG
)
3467 String aName
= aNameEdit
.GetText();
3468 aName
.EraseLeadingChars().EraseTrailingChars();
3471 if ( !aOKBtn
.IsEnabled() )
3472 aOKBtn
.Enable( sal_True
);
3476 if ( aOKBtn
.IsEnabled() )
3477 aOKBtn
.Enable( sal_False
);