1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/macros.h>
22 #include <svtools/PlaceEditDialog.hxx>
23 #include "PlacesListBox.hxx"
24 #include "fpsofficeResMgr.hxx"
25 #include <tools/stream.hxx>
26 #include <tools/urlobj.hxx>
27 #include <vcl/fixed.hxx>
28 #include <vcl/lstbox.hxx>
29 #include <vcl/msgbox.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/timer.hxx>
32 #include <unotools/ucbhelper.hxx>
33 #include "svtools/ehdl.hxx"
34 #include "svl/urihelper.hxx"
35 #include "unotools/pathoptions.hxx"
36 #include "unotools/viewoptions.hxx"
37 #include "svtools/fileview.hxx"
38 #include "svtools/sfxecode.hxx"
39 #include "svtools/svtabbx.hxx"
40 #include "svtools/treelistentry.hxx"
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <unotools/localfilehelper.hxx>
44 #include "svtools/helpid.hrc"
45 #include <svtools/svtools.hrc>
46 #include "OfficeFilePicker.hrc"
48 #include "asyncfilepicker.hxx"
49 #include "iodlgimp.hxx"
50 #include "svtools/inettbc.hxx"
51 #include "unotools/syslocale.hxx"
52 #include "svtools/QueryFolderName.hxx"
53 #include <rtl/ustring.hxx>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
56 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
57 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
58 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
59 #include <com/sun/star/beans/PropertyValue.hpp>
60 #include <com/sun/star/sdbc/XResultSet.hpp>
61 #include <com/sun/star/sdbc/XRow.hpp>
62 #include <com/sun/star/util/URL.hpp>
63 #include <com/sun/star/uno/Exception.hpp>
64 #include <com/sun/star/uno/Reference.hxx>
65 #include <com/sun/star/util/XURLTransformer.hpp>
66 #include <com/sun/star/uno/RuntimeException.hpp>
67 #include <com/sun/star/beans/XPropertySet.hpp>
69 #include <comphelper/interaction.hxx>
70 #include <comphelper/processfactory.hxx>
71 #include <comphelper/string.hxx>
74 #include <vcl/waitobj.hxx>
76 #include <com/sun/star/task/InteractionHandler.hpp>
77 #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
78 #include "fpinteraction.hxx"
79 #include <osl/process.h>
81 #include <officecfg/Office/Common.hxx>
87 //#define AUTOSELECT_USERFILTER
88 // define this for the experimental feature of user-filter auto selection
89 // means if the user enters e.g. *.doc<enter>, and there is a filter which is responsible for *.doc files (only),
90 // then this filter is selected automatically
92 using namespace ::com::sun::star::beans
;
93 using namespace ::com::sun::star::frame
;
94 using namespace ::com::sun::star::ui::dialogs
;
95 using namespace ::com::sun::star::uno
;
96 using namespace ::com::sun::star::lang
;
97 using namespace ::com::sun::star::ucb
;
98 using namespace ::com::sun::star::container
;
99 using namespace ::com::sun::star::task
;
100 using namespace ::com::sun::star::sdbc
;
101 using namespace ::utl
;
102 using namespace ::svt
;
104 using namespace ExtendedFilePickerElementIds
;
105 using namespace CommonFilePickerElementIds
;
106 using namespace InternalFilePickerElementIds
;
108 #define IODLG_CONFIGNAME OUString("FileDialog")
109 #define IMPGRF_CONFIGNAME OUString("ImportGraphicDialog")
111 #define GET_DECODED_NAME(aObj) \
112 aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET )
114 // Time to wait while traveling in the filterbox until
115 // the browsebox gets filtered ( in ms).
116 #define TRAVELFILTER_TIMEOUT 750
118 #define WIDTH_ADDITION 15
120 // functions -------------------------------------------------------------
125 //-----------------------------------------------------------------------------
126 String
getMostCurrentFilter( SvtExpFileDlg_Impl
* pImpl
)
128 DBG_ASSERT( pImpl
, "invalid impl pointer" );
129 const SvtFileDialogFilter_Impl
* pFilter
= pImpl
->_pUserFilter
;
132 pFilter
= pImpl
->GetCurFilter();
137 return pFilter
->GetType();
140 //-----------------------------------------------------------------------------
141 sal_Bool
restoreCurrentFilter( SvtExpFileDlg_Impl
* _pImpl
)
143 DBG_ASSERT( _pImpl
->GetCurFilter(), "restoreCurrentFilter: no current filter!" );
144 DBG_ASSERT( _pImpl
->GetCurFilterDisplayName().Len(), "restoreCurrentFilter: no current filter (no display name)!" );
146 _pImpl
->SelectFilterListEntry( _pImpl
->GetCurFilterDisplayName() );
149 String sSelectedDisplayName
;
150 DBG_ASSERT( ( _pImpl
->GetSelectedFilterEntry( sSelectedDisplayName
) == _pImpl
->GetCurFilter() )
151 && ( sSelectedDisplayName
== _pImpl
->GetCurFilterDisplayName() ),
152 "restoreCurrentFilter: inconsistence!" );
154 return _pImpl
->m_bNeedDelayedFilterExecute
;
157 //-----------------------------------------------------------------------------
158 String
GetFsysExtension_Impl( const String
& rFile
, const String
& rLastFilterExt
)
160 xub_StrLen nDotPos
= rFile
.SearchBackward( '.' );
161 if ( nDotPos
!= STRING_NOTFOUND
)
163 if ( rLastFilterExt
.Len() )
165 if ( rFile
.Copy( nDotPos
+ 1 ).EqualsIgnoreCaseAscii( rLastFilterExt
) )
166 return String( rLastFilterExt
);
169 return String( rFile
.Copy( nDotPos
) );
174 //-----------------------------------------------------------------------------
175 void SetFsysExtension_Impl( String
& rFile
, const String
& rExtension
)
177 const sal_Unicode
* p0
= rFile
.GetBuffer();
178 const sal_Unicode
* p1
= p0
+ rFile
.Len() - 1;
179 while ( p1
>= p0
&& *p1
!= sal_Unicode( '.' ) )
182 // remove old extension
184 sal::static_int_cast
< xub_StrLen
>(
185 p1
- p0
+ 1 - ( rExtension
.Len() > 0 ? 0 : 1 ) ) );
186 else if ( rExtension
.Len() )
188 rFile
+= sal_Unicode( '.' );
192 //-----------------------------------------------------------------------------
193 // move the control with the given offset
194 void lcl_MoveControl( Control
* _pControl
, sal_Int32 _nDeltaX
, sal_Int32 _nDeltaY
, sal_Int32
* _pMaxY
= NULL
)
198 Point aNewPos
= _pControl
->GetPosPixel();
200 // adjust the vertical position
201 aNewPos
.Y() += _nDeltaY
;
202 if ( _pMaxY
&& ( aNewPos
.Y() > *_pMaxY
) )
203 *_pMaxY
= aNewPos
.Y();
205 // adjust the horizontal position
206 aNewPos
.X() += _nDeltaX
;
208 _pControl
->SetPosPixel( aNewPos
);
212 //-------------------------------------------------------------------------
213 void lcl_autoUpdateFileExtension( SvtFileDialog
* _pDialog
, const String
& _rLastFilterExt
)
215 // if auto extension is enabled ....
216 if ( _pDialog
->isAutoExtensionEnabled() )
218 // automatically switch to the extension of the (maybe just newly selected) extension
219 String aNewFile
= _pDialog
->getCurrentFileText( );
220 String aExt
= GetFsysExtension_Impl( aNewFile
, _rLastFilterExt
);
222 // but only if there already is an extension
225 // check if it is a real file extension, and not only the "post-dot" part in
227 sal_Bool bRealExtensions
= sal_True
;
228 if ( STRING_NOTFOUND
!= aExt
.Search( '/' ) )
229 bRealExtensions
= sal_False
;
230 else if ( STRING_NOTFOUND
!= aExt
.Search( '\\' ) )
231 bRealExtensions
= sal_False
;
234 // no easy way to tell, because the part containing the dot already is the last
235 // segment of the complete file name
236 // So we have to check if the file name denotes a folder or a file.
237 // For performance reasons, we do this for file urls only
238 INetURLObject
aURL( aNewFile
);
239 if ( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
242 if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aNewFile
, sURL
) )
243 aURL
= INetURLObject( sURL
);
245 if ( INET_PROT_FILE
== aURL
.GetProtocol() )
249 bRealExtensions
= !_pDialog
->ContentIsFolder( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
251 catch( const ::com::sun::star::uno::Exception
& )
253 DBG_WARNING( "Exception in lcl_autoUpdateFileExtension" );
258 if ( bRealExtensions
)
260 SetFsysExtension_Impl( aNewFile
, _pDialog
->GetDefaultExt() );
261 _pDialog
->setCurrentFileText( aNewFile
);
267 //-------------------------------------------------------------------------
268 sal_Bool
lcl_getHomeDirectory( const String
& _rForURL
, String
& /* [out] */ _rHomeDir
)
272 // now ask the content broker for a provider for this scheme
273 //=================================================================
276 // get the provider for the current scheme
277 Reference
< XContentProvider
> xProvider(
278 UniversalContentBroker::create(
279 comphelper::getProcessComponentContext() )->
280 queryContentProvider( _rForURL
) );
282 DBG_ASSERT( xProvider
.is(), "lcl_getHomeDirectory: could not find a (valid) content provider for the current URL!" );
283 Reference
< XPropertySet
> xProviderProps( xProvider
, UNO_QUERY
);
284 if ( xProviderProps
.is() )
286 Reference
< XPropertySetInfo
> xPropInfo
= xProviderProps
->getPropertySetInfo();
287 const OUString
sHomeDirPropertyName( "HomeDirectory" );
288 if ( !xPropInfo
.is() || xPropInfo
->hasPropertyByName( sHomeDirPropertyName
) )
290 OUString sHomeDirectory
;
291 xProviderProps
->getPropertyValue( sHomeDirPropertyName
) >>= sHomeDirectory
;
292 _rHomeDir
= sHomeDirectory
;
296 catch( const Exception
& )
298 OSL_FAIL( "lcl_getHomeDirectory: caught an exception!" );
300 return 0 < _rHomeDir
.Len();
303 //---------------------------------------------------------------------
304 static String
lcl_ensureFinalSlash( const String
& _rDir
)
306 INetURLObject
aWorkPathObj( _rDir
, INET_PROT_FILE
);
307 aWorkPathObj
.setFinalSlash();
308 return aWorkPathObj
.GetMainURL( INetURLObject::NO_DECODE
);
311 //---------------------------------------------------------------------
312 struct RemoveFinalSlash
: public ::std::unary_function
< String
, void >
314 void operator()( String
& _rURL
)
316 INetURLObject
aURL( _rURL
);
318 if ( aURL
.getSegmentCount() > 1 )
320 aURL
.removeFinalSlash( );
321 _rURL
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
325 // -----------------------------------------------------------------------
326 /** retrieves the value of an environment variable
327 @return <TRUE/> if and only if the retrieved string value is not empty
329 bool getEnvironmentValue( const sal_Char
* _pAsciiEnvName
, OUString
& _rValue
)
331 _rValue
= OUString();
332 OUString sEnvName
= OUString::createFromAscii( _pAsciiEnvName
);
333 osl_getEnvironment( sEnvName
.pData
, &_rValue
.pData
);
334 return !_rValue
.isEmpty();
338 //***************************************************************************
340 //***************************************************************************
342 struct ControlChain_Impl
345 ControlChain_Impl
* _pNext
;
346 sal_Bool _bHasOwnership
;
348 ControlChain_Impl( Window
* pControl
, ControlChain_Impl
* pNext
);
349 ~ControlChain_Impl();
352 //***************************************************************************
354 ControlChain_Impl::ControlChain_Impl
357 ControlChain_Impl
* pNext
359 : _pControl( pControl
),
361 _bHasOwnership( sal_True
)
365 //***************************************************************************
367 ControlChain_Impl::~ControlChain_Impl()
369 if ( _bHasOwnership
)
376 //*****************************************************************************
378 //*****************************************************************************
379 SvtFileDialog::SvtFileDialog
385 ModalDialog( _pParent
, SvtResId( DLG_FPICKER_EXPLORERFILE
) )
387 ,_pUserControls( NULL
)
388 ,_pCbReadOnly( NULL
)
390 ,_pCbPreviewBox( NULL
)
391 ,_pCbSelection( NULL
)
396 ,_pFileNotifier( NULL
)
397 ,_pImp( new SvtExpFileDlg_Impl( nBits
) )
398 ,_nExtraBits( nExtraBits
)
399 ,_bIsInExecute( sal_False
)
400 ,m_bInExecuteAsync( false )
401 ,m_bHasFilename( false )
402 ,m_context(comphelper::getProcessComponentContext())
407 //*****************************************************************************
409 SvtFileDialog::SvtFileDialog ( Window
* _pParent
, WinBits nBits
)
410 :ModalDialog( _pParent
, SvtResId( DLG_FPICKER_EXPLORERFILE
) )
411 ,_pUserControls( NULL
)
412 ,_pCbReadOnly( NULL
)
414 ,_pCbPreviewBox( NULL
)
415 ,_pCbSelection( NULL
)
420 ,_pFileNotifier( NULL
)
421 ,_pImp( new SvtExpFileDlg_Impl( nBits
) )
423 ,_bIsInExecute( sal_False
)
424 ,m_bHasFilename( false )
429 //*****************************************************************************
431 SvtFileDialog::~SvtFileDialog()
433 if ( _pImp
->_aIniKey
.Len() )
436 SvtViewOptions
aDlgOpt( E_DIALOG
, _pImp
->_aIniKey
);
437 aDlgOpt
.SetWindowState(OStringToOUString(GetWindowState(), osl_getThreadTextEncoding()));
438 String sUserData
= _pFileView
->GetConfigString();
439 aDlgOpt
.SetUserItem( OUString( "UserData" ),
440 makeAny( OUString( sUserData
) ) );
443 _pFileView
->SetSelectHdl( Link() );
445 // Save bookmarked places
446 if(_pImp
->_pPlaces
->IsUpdated()) {
447 const std::vector
<PlacePtr
> aPlaces
= _pImp
->_pPlaces
->GetPlaces();
448 Sequence
< OUString
> placesUrlsList(_pImp
->_pPlaces
->GetNbEditablePlaces());
449 Sequence
< OUString
> placesNamesList(_pImp
->_pPlaces
->GetNbEditablePlaces());
451 for(std::vector
<PlacePtr
>::const_iterator it
= aPlaces
.begin(); it
!= aPlaces
.end(); ++it
) {
452 if((*it
)->IsEditable()) {
453 placesUrlsList
[i
] = (*it
)->GetUrl();
454 placesNamesList
[i
] = (*it
)->GetName();
459 boost::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create(m_context
));
460 officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList
, batch
, m_context
);
461 officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList
, batch
, m_context
);
471 delete _pCbPreviewBox
;
472 delete _pCbSelection
;
477 delete _pUserControls
;
480 //*****************************************************************************
482 void SvtFileDialog::Init_Impl
487 m_aImages
= ImageList( SvtResId( RID_FILEPICKER_IMAGES
) );
489 _pImp
->_nStyle
= nStyle
;
490 _pImp
->_a6Size
= LogicToPixel( Size( 6, 6 ), MAP_APPFONT
);
491 _pImp
->_eMode
= ( nStyle
& WB_SAVEAS
) ? FILEDLG_MODE_SAVE
: FILEDLG_MODE_OPEN
;
492 _pImp
->_eDlgType
= FILEDLG_TYPE_FILEDLG
;
494 if ( ( nStyle
& SFXWB_PATHDIALOG
) == SFXWB_PATHDIALOG
)
495 _pImp
->_eDlgType
= FILEDLG_TYPE_PATHDLG
;
497 // Set the directory for the "back to the default dir" button
498 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
499 SetStandardDir( aStdDirObj
.GetMainURL( INetURLObject::NO_DECODE
) );
502 if ( !( nStyle
& SFXWB_NOREMOTE
) )
504 _pImp
->_nState
|= FILEDLG_STATE_REMOTE
;
507 // Create control element, the order defines the tab control.
508 _pImp
->_pFtFileName
= new FixedText( this, SvtResId( FT_EXPLORERFILE_FILENAME
) );
510 SvtURLBox
* pURLBox
= new SvtURLBox( this, SvtResId( ED_EXPLORERFILE_FILENAME
) );
511 _pImp
->_pEdFileName
= pURLBox
;
512 _pImp
->_pEdFileName
->Show();
513 pURLBox
->SetSelectHdl( LINK( this, SvtFileDialog
, EntrySelectHdl_Impl
) );
514 pURLBox
->SetOpenHdl( STATIC_LINK( this, SvtFileDialog
, OpenHdl_Impl
) );
516 // in folder picker mode, only auto-complete directories (no files)
517 bool bIsFolderPicker
= ( _pImp
->_eDlgType
== FILEDLG_TYPE_PATHDLG
);
518 pURLBox
->SetOnlyDirectories( bIsFolderPicker
);
520 // in save mode, don't use the autocompletion as selection in the edit part
521 bool bSaveMode
= ( FILEDLG_MODE_SAVE
== _pImp
->_eMode
);
522 pURLBox
->SetNoURLSelection( bSaveMode
);
524 _pImp
->_pEdFileName
->SetHelpId( HID_FILEDLG_AUTOCOMPLETEBOX
);
526 _pImp
->_pFtFileType
= new FixedText( this, SvtResId( FT_EXPLORERFILE_FILETYPE
) );
527 _pImp
->CreateFilterListControl( this, SvtResId( LB_EXPLORERFILE_FILETYPE
) );
529 // move the filter listbox to the space occupied by the version listbox
530 // if that box isn't needed
531 if ( !( _nExtraBits
& SFX_EXTRA_SHOWVERSIONS
) &&
532 !( _nExtraBits
& SFX_EXTRA_TEMPLATES
) &&
533 !( _nExtraBits
& SFX_EXTRA_IMAGE_TEMPLATE
) )
536 FixedText
aSharedListBoxLabel( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
537 _pImp
->_pFtFileType
->SetPosPixel( aSharedListBoxLabel
.GetPosPixel() );
541 ListBox
aSharedListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
542 _pImp
->GetFilterListControl()->SetPosPixel( aSharedListBox
.GetPosPixel() );
546 _pImp
->_pEdCurrentPath
= new SvtURLBox( this, SvtResId(ED_EXPLORERFILE_CURRENTPATH
) );
547 _pImp
->_pEdCurrentPath
->Show();
549 _pImp
->_pBtnFileOpen
= new PushButton( this, SvtResId( BTN_EXPLORERFILE_OPEN
) );
550 _pImp
->_pBtnCancel
= new CancelButton( this, SvtResId( BTN_EXPLORERFILE_CANCEL
) );
551 _pImp
->_pBtnHelp
= new HelpButton( this, SvtResId( BTN_EXPLORERFILE_HELP
) );
553 _pImp
->_pBtnConnectToServer
= new PushButton ( this, SvtResId ( BTN_EXPLORERFILE_CONNECT_TO_SERVER
) );
554 _pImp
->_pBtnConnectToServer
->SetAccessibleName( _pImp
->_pBtnConnectToServer
->GetQuickHelpText() );
556 _pImp
->_pBtnUp
= new SvtUpButton_Impl( this, SvtResId( BTN_EXPLORERFILE_UP
) );
557 _pImp
->_pBtnNewFolder
= new ImageButton( this, SvtResId( BTN_EXPLORERFILE_NEWFOLDER
) );
558 _pImp
->_pBtnNewFolder
->SetStyle( _pImp
->_pBtnNewFolder
->GetStyle() | WB_NOPOINTERFOCUS
);
560 _pImp
->_pBtnUp
->SetAccessibleName( _pImp
->_pBtnUp
->GetQuickHelpText() );
561 _pImp
->_pBtnNewFolder
->SetAccessibleName( _pImp
->_pBtnNewFolder
->GetQuickHelpText() );
563 if ( ( nStyle
& SFXWB_MULTISELECTION
) == SFXWB_MULTISELECTION
)
564 _pImp
->_bMultiSelection
= sal_True
;
566 _pFileView
= new SvtFileView( this, SvtResId( CTL_EXPLORERFILE_FILELIST
),
567 FILEDLG_TYPE_PATHDLG
== _pImp
->_eDlgType
,
568 _pImp
->_bMultiSelection
);
569 _pFileView
->EnableAutoResize();
571 _pFileView
->SetHelpId( HID_FILEDLG_STANDARD
);
572 _pFileView
->SetStyle( _pFileView
->GetStyle() | WB_TABSTOP
);
574 _pSplitter
= new Splitter( this, SvtResId( EXPLORERFILE_SPLITTER
) );
575 _pSplitter
->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
576 _pSplitter
->SetSplitHdl( LINK( this, SvtFileDialog
, Split_Hdl
) );
578 // determine the size of the buttons
579 Size aSize
= _pImp
->_pBtnNewFolder
->GetSizePixel();
580 Image
aNewFolderImg( GetButtonImage( IMG_FILEDLG_CREATEFOLDER
) );
581 _pImp
->_pBtnNewFolder
->SetModeImage( aNewFolderImg
);
583 // set position of the buttons
584 Size aDlgSize
= GetOutputSizePixel();
585 long n6AppFontInPixel
=
586 LogicToPixel( Size( 6, 0 ), MAP_APPFONT
).Width();
587 long n3AppFontInPixel
=
588 LogicToPixel( Size( 3, 0 ), MAP_APPFONT
).Width();
589 long nHalf3AppFontInPixel
= n3AppFontInPixel
/2;
591 // nDelta is the space between the right border and the left border of the
592 // component currently positioned
593 long nDelta
= n6AppFontInPixel
;
597 aDlgSize
.Width() - nDelta
,
598 _pImp
->_pBtnNewFolder
->GetPosPixel().Y()
600 nDelta
+= aSize
.Width() + nHalf3AppFontInPixel
;
601 aPos
.X() = aDlgSize
.Width() - nDelta
;
602 _pImp
->_pBtnNewFolder
->SetPosPixel(aPos
);
604 // Previous level (up)
605 nDelta
+= aSize
.Width() + nHalf3AppFontInPixel
;
606 aPos
.X() = aDlgSize
.Width() - nDelta
;
607 _pImp
->_pBtnUp
->SetPosPixel(aPos
);
609 // Connect to server ("...")
610 nDelta
+= _pImp
->_pBtnConnectToServer
->GetSizePixel().Width() + nHalf3AppFontInPixel
;
611 aPos
.X() = aDlgSize
.Width() - nDelta
;
612 _pImp
->_pBtnConnectToServer
->SetPosPixel(aPos
);
614 // Set the size of the URL bar
615 nDelta
+= nHalf3AppFontInPixel
; // right margin of the URL bar
616 aSize
.Width() = aDlgSize
.Width()
617 - _pImp
->_pEdCurrentPath
->GetPosPixel().X()
619 _pImp
->_pEdCurrentPath
->SetOutputSizePixel(aSize
);
621 aPos
.X() = _pImp
->_pEdCurrentPath
->GetPosPixel().X();
622 _pImp
->_pEdCurrentPath
->SetPosPixel(aPos
);
624 if ( nStyle
& SFXWB_READONLY
)
626 _pCbReadOnly
= new CheckBox( this, SvtResId( CB_EXPLORERFILE_READONLY
) );
627 _pCbReadOnly
->SetHelpId( HID_FILEOPEN_READONLY
);
628 _pCbReadOnly
->SetText( SvtResId( STR_SVT_FILEPICKER_READONLY
) );
629 AddControl( _pCbReadOnly
);
630 ReleaseOwnership( _pCbReadOnly
);
631 _pCbReadOnly
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
634 if ( nStyle
& SFXWB_PASSWORD
)
636 _pImp
->_pCbPassword
= new CheckBox( this, SvtResId( CB_EXPLORERFILE_PASSWORD
) );
637 _pImp
->_pCbPassword
->SetText( SvtResId( STR_SVT_FILEPICKER_PASSWORD
) );
638 AddControl( _pImp
->_pCbPassword
);
639 ReleaseOwnership( _pImp
->_pCbPassword
);
640 _pImp
->_pCbPassword
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
643 // set the ini file for extracting the size
644 _pImp
->_aIniKey
= IODLG_CONFIGNAME
;
648 // Determine the amount of pixel the other elements have to be adjusted in their position.
649 aPos
.Y() += aSize
.Height();
650 aPos
.Y() += LogicToPixel( Size( 0, 6 ), MAP_APPFONT
).Height();
651 long nYOffset
= aPos
.Y();
652 aPos
= _pFileView
->GetPosPixel();
655 nYOffset
-= aPos
.Y();
657 // Adjust the position of the other elements.
658 _pFileView
->SetPosPixel( aPos
);
660 aPos
.X() = _pSplitter
->GetPosPixel().X();
661 _pSplitter
->SetPosPixel( aPos
);
663 aPos
.X() = _pImp
->_pPlaces
->GetPosPixel().X();
664 _pImp
->_pPlaces
->SetPosPixel( aPos
);
667 lcl_MoveControl( _pImp
->_pFtFileName
, 0, nYOffset
);
668 lcl_MoveControl( _pImp
->_pEdFileName
, 0, nYOffset
);
670 lcl_MoveControl( _pImp
->_pFtFileVersion
, 0, nYOffset
);
671 lcl_MoveControl( _pImp
->_pLbFileVersion
, 0, nYOffset
);
673 lcl_MoveControl( _pImp
->_pFtTemplates
, 0, nYOffset
);
674 lcl_MoveControl( _pImp
->_pLbTemplates
, 0, nYOffset
);
676 lcl_MoveControl( _pImp
->_pFtImageTemplates
, 0, nYOffset
);
677 lcl_MoveControl( _pImp
->_pLbImageTemplates
, 0, nYOffset
);
679 lcl_MoveControl( _pImp
->_pFtFileType
, 0, nYOffset
);
680 lcl_MoveControl( _pImp
->GetFilterListControl(), 0, nYOffset
);
682 lcl_MoveControl( _pImp
->_pBtnFileOpen
, 0, nYOffset
);
683 lcl_MoveControl( _pImp
->_pBtnCancel
, 0, nYOffset
);
685 lcl_MoveControl( _pImp
->_pBtnHelp
, 0, nYOffset
+ 3 );
686 // a little more spacing between Cancel- and HelpButton
688 // adjust size of the dialog
689 aSize
= GetSizePixel();
690 aSize
.Height() += nYOffset
;
691 SetSizePixel( aSize
);
693 // adjust the labels to the mode
694 sal_uInt16 nResId
= STR_EXPLORERFILE_OPEN
;
695 sal_uInt16 nButtonResId
= 0;
697 if ( nStyle
& WB_SAVEAS
)
699 nResId
= STR_EXPLORERFILE_SAVE
;
700 nButtonResId
= STR_EXPLORERFILE_BUTTONSAVE
;
703 if ( ( nStyle
& SFXWB_PATHDIALOG
) == SFXWB_PATHDIALOG
)
705 _pImp
->_pFtFileName
->SetText( SvtResId( STR_PATHNAME
) );
706 nResId
= STR_PATHSELECT
;
707 nButtonResId
= STR_BUTTONSELECT
;
710 SetText( SvtResId( nResId
) );
713 _pImp
->_pBtnFileOpen
->SetText( SvtResId( nButtonResId
) );
715 if ( FILEDLG_TYPE_FILEDLG
!= _pImp
->_eDlgType
)
717 _pImp
->_pFtFileType
->Hide();
718 _pImp
->GetFilterListControl()->Hide();
721 // Setting preferences of the control elements.
722 _pImp
->_pBtnNewFolder
->SetClickHdl( STATIC_LINK( this, SvtFileDialog
, NewFolderHdl_Impl
) );
723 _pImp
->_pBtnFileOpen
->SetClickHdl( STATIC_LINK( this, SvtFileDialog
, OpenHdl_Impl
) );
724 _pImp
->_pBtnCancel
->SetClickHdl( LINK( this, SvtFileDialog
, CancelHdl_Impl
) );
725 _pImp
->SetFilterListSelectHdl( STATIC_LINK( this, SvtFileDialog
, FilterSelectHdl_Impl
) );
726 _pImp
->_pEdFileName
->SetGetFocusHdl( STATIC_LINK( this, SvtFileDialog
, FileNameGetFocusHdl_Impl
) );
727 _pImp
->_pEdFileName
->SetModifyHdl( STATIC_LINK( this, SvtFileDialog
, FileNameModifiedHdl_Impl
) );
728 _pImp
->_pEdCurrentPath
->SetOpenHdl ( STATIC_LINK( this, SvtFileDialog
, URLBoxModifiedHdl_Impl
) );
729 _pImp
->_pBtnConnectToServer
->SetClickHdl( STATIC_LINK ( this, SvtFileDialog
, ConnectToServerPressed_Hdl
) );
732 _pFileView
->SetSelectHdl( LINK( this, SvtFileDialog
, SelectHdl_Impl
) );
733 _pFileView
->SetDoubleClickHdl( LINK( this, SvtFileDialog
, DblClickHdl_Impl
) );
734 _pFileView
->SetOpenDoneHdl( LINK( this, SvtFileDialog
, OpenDoneHdl_Impl
) );
738 // set timer for the filterbox travel
739 _pImp
->_aFilterTimer
.SetTimeout( TRAVELFILTER_TIMEOUT
);
740 _pImp
->_aFilterTimer
.SetTimeoutHdl( STATIC_LINK( this, SvtFileDialog
, FilterSelectHdl_Impl
) );
742 if ( WB_SAVEAS
& nStyle
)
744 // different help ids if in save-as mode
745 SetHelpId( HID_FILESAVE_DIALOG
);
747 _pImp
->_pEdFileName
->SetHelpId( HID_FILESAVE_FILEURL
);
748 _pImp
->_pBtnFileOpen
->SetHelpId( HID_FILESAVE_DOSAVE
);
749 _pImp
->_pBtnNewFolder
->SetHelpId( HID_FILESAVE_CREATEDIRECTORY
);
750 _pImp
->_pBtnUp
->SetHelpId( HID_FILESAVE_LEVELUP
);
751 _pImp
->GetFilterListControl()->SetHelpId( HID_FILESAVE_FILETYPE
);
752 _pFileView
->SetHelpId( HID_FILESAVE_FILEVIEW
);
754 // formerly, there was only _pLbFileVersion, which was used for 3 different
755 // use cases. For reasons of maintainability, I introduced extra members (_pLbTemplates, _pLbImageTemplates)
756 // for the extra use cases, and separated _pLbFileVersion
757 // I did not find out in which cases the help ID is really needed HID_FILESAVE_TEMPLATE - all
758 // tests I made lead to a dialog where _no_ of the three list boxes was present.
759 if ( _pImp
->_pLbFileVersion
)
760 _pImp
->_pLbFileVersion
->SetHelpId( HID_FILESAVE_TEMPLATE
);
761 if ( _pImp
->_pLbTemplates
)
762 _pImp
->_pLbTemplates
->SetHelpId( HID_FILESAVE_TEMPLATE
);
763 if ( _pImp
->_pLbImageTemplates
)
764 _pImp
->_pLbImageTemplates
->SetHelpId( HID_FILESAVE_TEMPLATE
);
766 if ( _pImp
->_pCbPassword
) _pImp
->_pCbPassword
->SetHelpId( HID_FILESAVE_SAVEWITHPASSWORD
);
767 if ( _pImp
->_pCbAutoExtension
) _pImp
->_pCbAutoExtension
->SetHelpId( HID_FILESAVE_AUTOEXTENSION
);
768 if ( _pImp
->_pCbOptions
) _pImp
->_pCbOptions
->SetHelpId( HID_FILESAVE_CUSTOMIZEFILTER
);
769 if ( _pCbSelection
) _pCbSelection
->SetHelpId( HID_FILESAVE_SELECTION
);
772 // correct the z-order of the controls
773 implArrangeControls();
775 /// read our settings from the configuration
776 m_aConfiguration
= OConfigurationTreeRoot::createWithComponentContext(
777 ::comphelper::getProcessComponentContext(),
778 OUString( "/org.openoffice.Office.UI/FilePicker" )
782 //*****************************************************************************
784 IMPL_STATIC_LINK( SvtFileDialog
, NewFolderHdl_Impl
, PushButton
*, EMPTYARG
)
786 pThis
->_pFileView
->EndInplaceEditing( false );
788 SmartContent
aContent( pThis
->_pFileView
->GetViewURL( ) );
790 aContent
.getTitle( aTitle
);
791 svtools::QueryFolderNameDialog
aDlg( pThis
, aTitle
, String( SvtResId( STR_SVT_NEW_FOLDER
) ) );
792 sal_Bool bHandled
= sal_False
;
796 if ( aDlg
.Execute() == RET_OK
)
798 OUString aUrl
= aContent
.createFolder( aDlg
.GetName( ) );
799 if ( !aUrl
.isEmpty( ) )
801 pThis
->_pFileView
->CreatedFolder( aUrl
, aDlg
.GetName() );
812 //*****************************************************************************
814 IMPL_STATIC_LINK_NOINSTANCE( SvtFileDialog
, ViewHdl_Impl
, ImageButton
*, EMPTYARG
)
819 //-----------------------------------------------------------------------------
820 sal_Bool
SvtFileDialog::createNewUserFilter( const String
& _rNewFilter
, sal_Bool _bAllowUserDefExt
)
822 // delete the old user filter and create a new one
823 DELETEZ( _pImp
->_pUserFilter
);
824 _pImp
->_pUserFilter
= new SvtFileDialogFilter_Impl( _rNewFilter
, _rNewFilter
);
826 // remember the extension
827 sal_Bool bIsAllFiles
= _rNewFilter
.EqualsAscii( FILEDIALOG_FILTER_ALL
);
831 SetDefaultExt( _rNewFilter
.Copy( 2 ) );
832 // TODO: this is nonsense. In the whole file there are a lotta places where we assume that a user filter
833 // is always "*.<something>". But changing this would take some more time than I have now ...
835 // now, the default extension is set to the one of the user filter (or empty)
836 // if the former is not allowed (_bAllowUserDefExt = <FALSE/>), we have to use the ext of the current filter
838 sal_Bool bUseCurFilterExt
= sal_True
;
839 String sUserFilter
= _pImp
->_pUserFilter
->GetType();
840 xub_StrLen nSepPos
= sUserFilter
.SearchBackward( '.' );
841 if ( STRING_NOTFOUND
!= nSepPos
)
843 String sUserExt
= sUserFilter
.Copy( nSepPos
+ 1 );
844 if ( ( STRING_NOTFOUND
== sUserExt
.Search( '*' ) )
845 && ( STRING_NOTFOUND
== sUserExt
.Search( '?' ) )
847 bUseCurFilterExt
= sal_False
;
850 if ( !_bAllowUserDefExt
|| bUseCurFilterExt
)
852 if ( _pImp
->GetCurFilter( ) )
853 SetDefaultExt( _pImp
->GetCurFilter( )->GetExtension() );
862 //-----------------------------------------------------------------------------
863 #define FLT_NONEMPTY 0x0001
864 #define FLT_CHANGED 0x0002
865 #define FLT_USERFILTER 0x0004
866 #define FLT_ALLFILESFILTER 0x0008
868 //-----------------------------------------------------------------------------
869 sal_uInt16
SvtFileDialog::adjustFilter( const String
& _rFilter
)
871 sal_uInt16 nReturn
= 0;
873 const sal_Bool bNonEmpty
= ( _rFilter
.Len() != 0 );
876 nReturn
|= FLT_NONEMPTY
;
878 sal_Bool bFilterChanged
= sal_True
;
880 // search for a corresponding filter
881 SvtFileDialogFilter_Impl
* pFilter
= FindFilter_Impl( _rFilter
, sal_False
, bFilterChanged
);
883 #ifdef AUTOSELECT_USERFILTER
884 // if we found a filter which without allowing multi-extensions -> select it
887 _pImp
->SelectFilterListEntry( pFilter
->GetName() );
888 _pImp
->SetCurFilter( pFilter
);
890 #endif // AUTOSELECT_USERFILTER
892 // look for multi-ext filters if necessary
894 pFilter
= FindFilter_Impl( _rFilter
, sal_True
, bFilterChanged
);
896 if ( bFilterChanged
)
897 nReturn
|= FLT_CHANGED
;
901 nReturn
|= FLT_USERFILTER
;
902 // no filter found : use it as user defined filter
903 #ifdef AUTOSELECT_USERFILTER
904 if ( createNewUserFilter( _rFilter
, sal_True
) )
906 if ( createNewUserFilter( _rFilter
, sal_False
) )
908 { // it's the "all files" filter
909 nReturn
|= FLT_ALLFILESFILTER
;
911 #ifdef AUTOSELECT_USERFILTER
912 // select the "all files" entry
913 String
sAllFilesFilter( SvtResId( STR_FILTERNAME_ALL
) );
914 if ( _pImp
->HasFilterListEntry( sAllFilesFilter
) )
916 _pImp
->SelectFilterListEntry( sAllFilesFilter
);
917 _pImp
->SetCurFilter( _pImp
->GetSelectedFilterEntry( sAllFilesFilter
) );
920 _pImp
->SetNoFilterListSelection( ); // there is no "all files" entry
921 #endif // AUTOSELECT_USERFILTER
923 #ifdef AUTOSELECT_USERFILTER
925 _pImp
->SetNoFilterListSelection( );
926 #endif // AUTOSELECT_USERFILTER
933 //-----------------------------------------------------------------------------
934 IMPL_LINK_NOARG(SvtFileDialog
, CancelHdl_Impl
)
936 if ( m_pCurrentAsyncAction
.is() )
938 m_pCurrentAsyncAction
->cancel();
939 onAsyncOperationFinished();
943 EndDialog( sal_False
);
948 //-----------------------------------------------------------------------------
949 IMPL_STATIC_LINK( SvtFileDialog
, OpenHdl_Impl
, void*, pVoid
)
951 if ( pThis
->_pImp
->_bMultiSelection
&& pThis
->_pFileView
->GetSelectionCount() > 1 )
953 // special open in case of multiselection
954 pThis
->OpenMultiSelection_Impl();
959 String
aOldPath( pThis
->_pFileView
->GetViewURL() );
960 if ( pThis
->_pImp
->_bDoubleClick
|| pThis
->_pFileView
->HasChildPathFocus() )
961 // Selection done by doubleclicking in the view, get filename from the view
962 aFileName
= pThis
->_pFileView
->GetCurrentURL();
964 if ( !aFileName
.Len() )
966 // if an entry is selected in the view ....
967 if ( pThis
->_pFileView
->GetSelectionCount() )
968 { // -> use this one. This will allow us to step down this folder
969 aFileName
= pThis
->_pFileView
->GetCurrentURL();
973 if ( !aFileName
.Len() )
975 if ( pThis
->_pImp
->_eMode
== FILEDLG_MODE_OPEN
&& pThis
->_pImp
->_pEdFileName
->IsTravelSelect() )
976 // OpenHdl called from URLBox; travelling through the list of URLs should not cause an opening
977 return 0; // MBA->PB: seems to be called never ?!
979 // get the URL from from the edit field ( if not empty )
980 if ( !pThis
->_pImp
->_pEdFileName
->GetText().isEmpty() )
982 String aText
= pThis
->_pImp
->_pEdFileName
->GetText();
984 // did we reach the root?
985 if ( !INetURLObject( aOldPath
).getSegmentCount() )
987 if ( ( aText
.Len() == 2 && aText
.EqualsAscii( ".." ) ) ||
988 ( aText
.Len() == 3 && ( aText
.EqualsAscii( "..\\" ) || aText
.EqualsAscii( "../" ) ) ) )
989 // don't go higher than the root
994 if ( ( 1 == aText
.Len() ) && ( '~' == aText
.GetBuffer()[0] ) )
996 // go to the home directory
997 if ( lcl_getHomeDirectory( pThis
->_pFileView
->GetViewURL(), aFileName
) )
998 // in case we got a home dir, reset the text of the edit
999 pThis
->_pImp
->_pEdFileName
->SetText( String() );
1001 if ( !aFileName
.Len() )
1004 // get url from autocomplete edit
1005 aFileName
= pThis
->_pImp
->_pEdFileName
->GetURL();
1008 else if ( pVoid
== pThis
->_pImp
->_pBtnFileOpen
)
1009 // OpenHdl was called for the "Open" Button; if edit field is empty, use selected element in the view
1010 aFileName
= pThis
->_pFileView
->GetCurrentURL();
1014 if ( !aFileName
.Len() && pVoid
== pThis
->_pImp
->_pEdFileName
&& pThis
->_pImp
->_pUserFilter
)
1016 DELETEZ( pThis
->_pImp
->_pUserFilter
);
1020 sal_uInt16 nLen
= aFileName
.Len();
1023 // if the dialog was opened to select a folder, the last selected folder should be selected
1024 if( pThis
->_pImp
->_eDlgType
== FILEDLG_TYPE_PATHDLG
)
1026 aFileName
= pThis
->_pImp
->_pEdCurrentPath
->GetText();
1027 nLen
= aFileName
.Len();
1030 // no file selected !
1034 // mark input as selected
1035 pThis
->_pImp
->_pEdFileName
->SetSelection( Selection( 0, nLen
) );
1037 // if a path with wildcards is given, divide the string into path and wildcards
1039 if ( !pThis
->IsolateFilterFromPath_Impl( aFileName
, aFilter
) )
1042 // if a filter was retrieved, there were wildcards !
1043 sal_uInt16 nNewFilterFlags
= pThis
->adjustFilter( aFilter
);
1044 if ( nNewFilterFlags
& FLT_CHANGED
)
1046 // cut off all text before wildcard in edit and select wildcard
1047 pThis
->_pImp
->_pEdFileName
->SetText( aFilter
);
1048 pThis
->_pImp
->_pEdFileName
->SetSelection( Selection( 0, aFilter
.Len() ) );
1052 INetURLObject
aFileObject( aFileName
);
1053 if ( ( aFileObject
.GetProtocol() == INET_PROT_NOT_VALID
) && aFileName
.Len() )
1055 String sCompleted
= SvtURLBox::ParseSmart( aFileName
, pThis
->_pFileView
->GetViewURL(), SvtPathOptions().GetWorkPath() );
1056 if ( sCompleted
.Len() )
1057 aFileName
= sCompleted
;
1061 // check if it is a folder
1062 sal_Bool bIsFolder
= sal_False
;
1064 // first thing before doing anyhing with the content: Reset it. When the user presses "open" (or "save" or "export",
1065 // for that matter), s/he wants the complete handling, including all possible error messages, even if s/he
1066 // does the same thing for the same content twice, s/he wants both fails to be displayed.
1067 // Without the reset, it could be that the content cached all relevant information, and will not display any
1068 // error messages for the same content a second time ....
1069 pThis
->m_aContent
.bindTo( OUString( ) );
1071 if ( aFileName
.Len() )
1073 // Make sure we have own Interaction Handler in place. We do not need
1074 // to intercept interactions here, but to record the fact that there
1075 // was an interaction.
1076 SmartContent::InteractionHandlerType eInterActionHandlerType
1077 = pThis
->m_aContent
.queryCurrentInteractionHandler();
1078 if ( ( eInterActionHandlerType
== SmartContent::IHT_NONE
) ||
1079 ( eInterActionHandlerType
== SmartContent::IHT_DEFAULT
) )
1080 pThis
->m_aContent
.enableOwnInteractionHandler(
1081 OFilePickerInteractionHandler::E_NOINTERCEPTION
);
1083 bIsFolder
= pThis
->m_aContent
.isFolder( aFileName
);
1085 // access denied to the given resource - and interaction was already
1086 // used => break following operations
1087 OFilePickerInteractionHandler
* pHandler
1088 = pThis
->m_aContent
.getOwnInteractionHandler();
1090 OSL_ENSURE( pHandler
, "Got no Interaction Handler!!!" );
1092 if ( pHandler
->wasAccessDenied() )
1095 if ( pThis
->m_aContent
.isInvalid() &&
1096 ( pThis
->_pImp
->_eMode
== FILEDLG_MODE_OPEN
) )
1098 if ( !pHandler
->wasUsed() )
1099 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS
);
1104 // restore previous Interaction Handler
1105 if ( eInterActionHandlerType
== SmartContent::IHT_NONE
)
1106 pThis
->m_aContent
.disableInteractionHandler();
1107 else if ( eInterActionHandlerType
== SmartContent::IHT_DEFAULT
)
1108 pThis
->m_aContent
.enableDefaultInteractionHandler();
1111 if ( !bIsFolder
// no existent folder
1112 && pThis
->_pImp
->_pCbAutoExtension
// auto extension is enabled in general
1113 && pThis
->_pImp
->_pCbAutoExtension
->IsChecked() // auto extension is really to be used
1114 && pThis
->GetDefaultExt().Len() // there is a default extension
1115 && !comphelper::string::equals(pThis
->GetDefaultExt(), '*') // the default extension is not "all"
1116 && !( FILEDLG_MODE_SAVE
== pThis
->_pImp
->_eMode
// we're saving a file
1117 && pThis
->_pFileView
->GetSelectionCount() // there is a selected file in the file view -> it will later on
1118 ) // (in SvtFileDialog::GetPathList) be taken as file to save to
1120 && FILEDLG_MODE_OPEN
!= pThis
->_pImp
->_eMode
// #i83408# don't append extension on open
1123 // check extension and append the default extension if necessary
1124 appendDefaultExtension(aFileName
,
1125 pThis
->GetDefaultExt(),
1126 pThis
->_pImp
->GetCurFilter()->GetType());
1129 sal_Bool bOpenFolder
= ( FILEDLG_TYPE_PATHDLG
== pThis
->_pImp
->_eDlgType
) &&
1130 !pThis
->_pImp
->_bDoubleClick
&& pVoid
!= pThis
->_pImp
->_pEdFileName
;
1135 pThis
->_aPath
= aFileName
;
1139 if ( aFileName
!= pThis
->_pFileView
->GetViewURL() )
1141 pThis
->OpenURL_Impl( aFileName
);
1145 if ( nNewFilterFlags
& FLT_CHANGED
)
1146 pThis
->ExecuteFilter();
1152 else if ( !( nNewFilterFlags
& FLT_NONEMPTY
) )
1154 // if applicable save URL
1155 pThis
->_aPath
= aFileName
;
1159 // if applicable filter again
1160 if ( nNewFilterFlags
& FLT_CHANGED
)
1161 pThis
->ExecuteFilter();
1165 INetURLObject
aFileObj( aFileName
);
1166 if ( aFileObj
.HasError() )
1168 ErrorHandler::HandleError( ERRCODE_IO_GENERAL
);
1172 switch ( pThis
->_pImp
->_eMode
)
1174 case FILEDLG_MODE_SAVE
:
1176 if ( ::utl::UCBContentHelper::Exists( aFileObj
.GetMainURL( INetURLObject::NO_DECODE
) ) )
1178 String aMsg
= SvtResId( STR_SVT_ALREADYEXISTOVERWRITE
);
1179 aMsg
.SearchAndReplace(
1180 String( RTL_CONSTASCII_USTRINGPARAM( "$filename$" ) ),
1181 aFileObj
.getName(INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
)
1183 QueryBox
aBox( pThis
, WB_YES_NO
, aMsg
);
1184 if ( aBox
.Execute() != RET_YES
)
1190 if ( ::utl::LocalFileHelper::ConvertURLToSystemPath( aFileName
, aCurPath
) )
1192 // if content does not exist: at least its path must exist
1193 INetURLObject aPathObj
= aFileObj
;
1194 aPathObj
.removeSegment();
1195 sal_Bool bFolder
= pThis
->m_aContent
.isFolder( aPathObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1198 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH
);
1206 case FILEDLG_MODE_OPEN
:
1208 // do an existence check herein, again
1210 if ( INET_PROT_FILE
== aFileObj
.GetProtocol( ) )
1212 sal_Bool bExists
= sal_False
;
1213 bExists
= pThis
->m_aContent
.is( aFileObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1218 String
sError( SvtResId( RID_FILEOPEN_NOTEXISTENTFILE
) );
1220 String
sInvalidFile( aFileObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
) );
1221 if ( INET_PROT_FILE
== aFileObj
.GetProtocol() )
1222 { // if it's a file URL, transform the URL into system notation
1223 OUString
sURL( sInvalidFile
);
1225 osl_getSystemPathFromFileURL( sURL
.pData
, &sSystem
.pData
);
1226 sInvalidFile
= sSystem
;
1228 sError
.SearchAndReplaceAscii( "$name$", sInvalidFile
);
1230 ErrorBox
aError( pThis
, WB_OK
, sError
);
1239 OSL_FAIL("SvtFileDialog, OpenHdl_Impl: invalid mode!");
1242 // notify interested parties
1245 if ( pThis
->_aOKHdl
.IsSet() )
1246 nRet
= pThis
->_aOKHdl
.Call( pThis
);
1252 pThis
->EndDialog( sal_True
);
1258 //*****************************************************************************
1260 void SvtFileDialog::EnableAutocompletion( sal_Bool _bEnable
)
1262 _pImp
->_pEdFileName
->EnableAutocompletion( _bEnable
);
1265 //*****************************************************************************
1267 IMPL_STATIC_LINK( SvtFileDialog
, FilterSelectHdl_Impl
, ListBox
*, pBox
)
1269 DBG_ASSERT( pBox
, "SvtFileDialog:keine Instanz" );
1271 // was the handler executed by the travel timer?
1272 if ( pBox
== (ListBox
*)&pThis
->_pImp
->_aFilterTimer
)
1274 // filter the view again
1275 pThis
->ExecuteFilter();
1279 String sSelectedFilterDisplayName
;
1280 SvtFileDialogFilter_Impl
* pSelectedFilter
= pThis
->_pImp
->GetSelectedFilterEntry( sSelectedFilterDisplayName
);
1281 if ( !pSelectedFilter
)
1282 { // there is no current selection. This happens if for instance the user selects a group separator using
1283 // the keyboard, and then presses enter: When the selection happens, we immediately deselect the entry,
1284 // so in this situation there is no current selection.
1285 if ( restoreCurrentFilter( pThis
->_pImp
) )
1286 pThis
->ExecuteFilter();
1290 if ( pSelectedFilter
->isGroupSeparator() )
1291 { // group separators can't be selected
1292 // return to the previously selected entry
1293 if ( pThis
->_pImp
->IsFilterListTravelSelect() )
1295 pThis
->_pImp
->SetNoFilterListSelection( );
1297 // stop the timer for executing the filter
1298 if ( pThis
->_pImp
->_aFilterTimer
.IsActive() )
1299 pThis
->_pImp
->m_bNeedDelayedFilterExecute
= sal_True
;
1300 pThis
->_pImp
->_aFilterTimer
.Stop();
1304 if ( restoreCurrentFilter( pThis
->_pImp
) )
1305 pThis
->ExecuteFilter();
1308 else if ( ( pSelectedFilter
!= pThis
->_pImp
->GetCurFilter() )
1309 || pThis
->_pImp
->_pUserFilter
1312 // Store the old filter for the auto extension handling
1313 String sLastFilterExt
= pThis
->_pImp
->GetCurFilter()->GetExtension();
1314 DELETEZ( pThis
->_pImp
->_pUserFilter
);
1316 // if applicable remove filter of the user
1317 pThis
->_pImp
->SetCurFilter( pSelectedFilter
, sSelectedFilterDisplayName
);
1319 // if applicable show extension
1320 pThis
->SetDefaultExt( pSelectedFilter
->GetExtension() );
1321 sal_uInt16 nSepPos
= pThis
->GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP
);
1323 if ( nSepPos
!= STRING_NOTFOUND
)
1324 pThis
->EraseDefaultExt( nSepPos
);
1326 // update the extension of the current file if necessary
1327 lcl_autoUpdateFileExtension( pThis
, sLastFilterExt
);
1329 // if the user is traveling fast through the filterbox
1330 // do not filter instantly
1331 if ( pThis
->_pImp
->IsFilterListTravelSelect() )
1333 // FilterSelectHdl_Impl should be started again in
1334 // TRAVELFILTER_TIMEOUT ms
1335 pThis
->_pImp
->_aFilterTimer
.Start();
1339 // stop previously started timer
1340 pThis
->_pImp
->_aFilterTimer
.Stop();
1342 // filter the view again
1343 pThis
->ExecuteFilter();
1351 //*****************************************************************************
1353 IMPL_STATIC_LINK( SvtFileDialog
, FileNameGetFocusHdl_Impl
, void*, EMPTYARG
)
1355 pThis
->_pFileView
->SetNoSelection();
1356 pThis
->_pFileView
->Update();
1360 //*****************************************************************************
1362 IMPL_STATIC_LINK( SvtFileDialog
, FileNameModifiedHdl_Impl
, void*, EMPTYARG
)
1364 FileNameGetFocusHdl_Impl( pThis
, NULL
);
1368 //*****************************************************************************
1370 IMPL_STATIC_LINK ( SvtFileDialog
, URLBoxModifiedHdl_Impl
, void*, EMPTYARG
)
1372 String _aPath
= pThis
->_pImp
->_pEdCurrentPath
->GetURL();
1373 pThis
->OpenURL_Impl(_aPath
);
1377 //*****************************************************************************
1379 IMPL_STATIC_LINK ( SvtFileDialog
, ConnectToServerPressed_Hdl
, void*, EMPTYARG
)
1381 pThis
->_pFileView
->EndInplaceEditing( false );
1383 PlaceEditDialog
aDlg( pThis
);
1384 short aRetCode
= aDlg
.Execute();
1389 PlacePtr newPlace
= aDlg
.GetPlace();
1390 pThis
->_pImp
->_pPlaces
->AppendPlace(newPlace
);
1403 //*****************************************************************************
1405 IMPL_LINK_NOARG ( SvtFileDialog
, AddPlacePressed_Hdl
)
1407 // Maybe open the PlacesDialog would have been a better idea
1408 // there is an ux choice to make we did not make...
1409 INetURLObject
aURLObj( _pFileView
->GetViewURL() );
1411 new Place( aURLObj
.GetLastName(INetURLObject::DECODE_WITH_CHARSET
),
1412 OUString(_pFileView
->GetViewURL()), true));
1413 _pImp
->_pPlaces
->AppendPlace(newPlace
);
1417 //*****************************************************************************
1419 IMPL_LINK_NOARG ( SvtFileDialog
, RemovePlacePressed_Hdl
)
1421 _pImp
->_pPlaces
->RemoveSelectedPlace();
1425 //*****************************************************************************
1427 SvtFileDialogFilter_Impl
* SvtFileDialog::FindFilter_Impl
1429 const String
& _rFilter
,
1430 sal_Bool _bMultiExt
,/* TRUE - regard filter with several extensions
1433 sal_Bool
& _rFilterChanged
1438 This method looks for the specified extension in the included filters.
1442 SvtFileDialogFilter_Impl
* pFoundFilter
= NULL
;
1443 SvtFileDialogFilterList_Impl
* pList
= _pImp
->_pFilter
;
1444 sal_uInt16 nFilter
= pList
->size();
1448 SvtFileDialogFilter_Impl
* pFilter
= &(*pList
)[ nFilter
];
1449 const String
& rType
= pFilter
->GetType();
1450 String aSingleType
= rType
;
1455 while ( !pFoundFilter
&& nIdx
!= -1 )
1457 aSingleType
= rType
.GetToken( 0, FILEDIALOG_DEF_EXTSEP
, nIdx
);
1459 if ( aSingleType
== _rFilter
)
1461 if ( aSingleType
.CompareIgnoreCaseToAscii( _rFilter
) == COMPARE_EQUAL
)
1463 pFoundFilter
= pFilter
;
1467 else if ( rType
== _rFilter
)
1469 else if ( rType
.CompareIgnoreCaseToAscii( _rFilter
) == COMPARE_EQUAL
)
1471 pFoundFilter
= pFilter
;
1476 _rFilterChanged
= _pImp
->_pUserFilter
|| ( _pImp
->GetCurFilter() != pFilter
);
1478 createNewUserFilter( _rFilter
, sal_False
);
1483 return pFoundFilter
;
1486 //*****************************************************************************
1488 void SvtFileDialog::ExecuteFilter()
1490 _pImp
->m_bNeedDelayedFilterExecute
= sal_False
;
1491 executeAsync( AsyncPickerAction::eExecuteFilter
, String(), getMostCurrentFilter( _pImp
) );
1494 //*****************************************************************************
1496 void SvtFileDialog::OpenMultiSelection_Impl()
1500 OpenHandler for MultiSelection
1504 sal_uLong nCount
= _pFileView
->GetSelectionCount();
1505 SvTreeListEntry
* pEntry
= nCount
? _pFileView
->FirstSelected() : NULL
;
1507 if ( nCount
&& pEntry
)
1508 _aPath
= _pFileView
->GetURL( pEntry
);
1510 // notify interested parties
1513 if ( _aOKHdl
.IsSet() )
1514 nRet
= _aOKHdl
.Call( this );
1519 EndDialog( sal_True
);
1522 //*****************************************************************************
1524 void SvtFileDialog::UpdateControls( const String
& rURL
)
1526 _pImp
->_pEdFileName
->SetBaseURL( rURL
);
1528 INetURLObject
aObj( rURL
);
1530 //=========================================================================
1533 DBG_ASSERT( INET_PROT_NOT_VALID
!= aObj
.GetProtocol(), "SvtFileDialog::UpdateControls: Invalid URL!" );
1535 if ( aObj
.getSegmentCount() )
1537 ::utl::LocalFileHelper::ConvertURLToSystemPath( rURL
, sText
);
1538 if ( !sText
.isEmpty() )
1540 // no Fsys path for server file system ( only UCB has mountpoints! )
1541 if ( INET_PROT_FILE
!= aObj
.GetProtocol() )
1542 sText
= rURL
.Copy( static_cast< sal_uInt16
>(
1543 INetURLObject::GetScheme( aObj
.GetProtocol() ).getLength() ) );
1546 if ( sText
.isEmpty() && aObj
.getSegmentCount() )
1551 if ( FILEDLG_TYPE_PATHDLG
== _pImp
->_eDlgType
)
1552 // -> set new path in the edit field
1553 _pImp
->_pEdFileName
->SetText( sText
);
1555 // in the "current path" field, truncate the trailing slash
1556 if ( aObj
.hasFinalSlash() )
1558 aObj
.removeFinalSlash();
1559 String
sURL( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1560 if ( !::utl::LocalFileHelper::ConvertURLToSystemPath( sURL
, sText
) )
1564 if ( sText
.isEmpty() && rURL
.Len() )
1565 // happens, for instance, for URLs which the INetURLObject does not know to belong to a hierarchical scheme
1567 _pImp
->_pEdCurrentPath
->SetText( sText
);
1570 //=========================================================================
1572 if ( _pFileNotifier
)
1573 _pFileNotifier
->notify( DIRECTORY_CHANGED
, 0 );
1576 //*****************************************************************************
1578 IMPL_LINK( SvtFileDialog
, SelectHdl_Impl
, SvTabListBox
*, pBox
)
1580 SvTreeListEntry
* pEntry
= pBox
->FirstSelected();
1581 DBG_ASSERT( pEntry
, "SelectHandler without selected entry" );
1582 SvtContentEntry
* pUserData
= (SvtContentEntry
*)pEntry
->GetUserData();
1586 INetURLObject
aObj( pUserData
->maURL
);
1587 if ( FILEDLG_TYPE_PATHDLG
== _pImp
->_eDlgType
)
1589 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
1591 if ( !pUserData
->mbIsFolder
)
1592 aObj
.removeSegment();
1593 String aName
= aObj
.getFSysPath( (INetURLObject::FSysStyle
)(INetURLObject::FSYS_DETECT
& ~INetURLObject::FSYS_VOS
) );
1594 _pImp
->_pEdFileName
->SetText( aName
);
1595 _pImp
->_pEdFileName
->SetSelection( Selection( 0, aName
.Len() ) );
1596 _aPath
= pUserData
->maURL
;
1598 else if ( !pUserData
->mbIsFolder
)
1600 _pImp
->_pEdFileName
->SetText( pUserData
->maURL
);
1601 _pImp
->_pEdFileName
->SetSelection( Selection( 0, pUserData
->maURL
.getLength() ) );
1602 _aPath
= pUserData
->maURL
;
1605 _pImp
->_pEdFileName
->SetText( OUString() );
1609 if ( !pUserData
->mbIsFolder
)
1611 String aName
= pBox
->GetEntryText( pEntry
, 0 );
1612 _pImp
->_pEdFileName
->SetText( aName
);
1613 _pImp
->_pEdFileName
->SetSelection( Selection( 0, aName
.Len() ) );
1614 _aPath
= pUserData
->maURL
;
1619 if ( _pImp
->_bMultiSelection
&& _pFileView
->GetSelectionCount() > 1 )
1621 // clear the file edit for multiselection
1622 _pImp
->_pEdFileName
->SetText( String() );
1630 //*****************************************************************************
1632 IMPL_LINK_NOARG(SvtFileDialog
, DblClickHdl_Impl
)
1634 _pImp
->_bDoubleClick
= sal_True
;
1635 OpenHdl_Impl( this, NULL
);
1636 _pImp
->_bDoubleClick
= sal_False
;
1641 //*****************************************************************************
1643 IMPL_LINK_NOARG(SvtFileDialog
, EntrySelectHdl_Impl
)
1650 //*****************************************************************************
1652 IMPL_LINK( SvtFileDialog
, OpenDoneHdl_Impl
, SvtFileView
*, pView
)
1654 String
sCurrentFolder( pView
->GetViewURL() );
1655 // check if we can create new folders
1656 EnableControl( _pImp
->_pBtnNewFolder
, ContentCanMakeFolder( sCurrentFolder
) );
1658 // check if we can travel one level up
1659 bool bCanTravelUp
= ContentHasParentFolder( pView
->GetViewURL() );
1662 // additional check: the parent folder should not be prohibited
1663 INetURLObject
aCurrentFolder( sCurrentFolder
);
1664 DBG_ASSERT( INET_PROT_NOT_VALID
!= aCurrentFolder
.GetProtocol(),
1665 "SvtFileDialog::OpenDoneHdl_Impl: invalid current URL!" );
1667 aCurrentFolder
.removeSegment();
1669 EnableControl( _pImp
->_pBtnUp
, bCanTravelUp
);
1674 //*****************************************************************************
1676 IMPL_LINK_NOARG(SvtFileDialog
, AutoExtensionHdl_Impl
)
1678 if ( _pFileNotifier
)
1679 _pFileNotifier
->notify( CTRL_STATE_CHANGED
,
1680 CHECKBOX_AUTOEXTENSION
);
1682 // update the extension of the current file if necessary
1683 lcl_autoUpdateFileExtension( this, _pImp
->GetCurFilter()->GetExtension() );
1688 //*****************************************************************************
1690 IMPL_LINK( SvtFileDialog
, ClickHdl_Impl
, CheckBox
*, pCheckBox
)
1692 if ( ! _pFileNotifier
)
1697 if ( pCheckBox
== _pImp
->_pCbOptions
)
1698 nId
= CHECKBOX_FILTEROPTIONS
;
1699 else if ( pCheckBox
== _pCbSelection
)
1700 nId
= CHECKBOX_SELECTION
;
1701 else if ( pCheckBox
== _pCbReadOnly
)
1702 nId
= CHECKBOX_READONLY
;
1703 else if ( pCheckBox
== _pImp
->_pCbPassword
)
1704 nId
= CHECKBOX_PASSWORD
;
1705 else if ( pCheckBox
== _pCbLinkBox
)
1706 nId
= CHECKBOX_LINK
;
1707 else if ( pCheckBox
== _pCbPreviewBox
)
1708 nId
= CHECKBOX_PREVIEW
;
1711 _pFileNotifier
->notify( CTRL_STATE_CHANGED
, nId
);
1716 //*****************************************************************************
1718 IMPL_LINK_NOARG(SvtFileDialog
, PlayButtonHdl_Impl
)
1720 if ( _pFileNotifier
)
1721 _pFileNotifier
->notify( CTRL_STATE_CHANGED
,
1727 //*****************************************************************************
1729 long SvtFileDialog::Notify( NotifyEvent
& rNEvt
)
1733 This method gets called to catch <BACKSPACE>.
1737 sal_uInt16 nType
= rNEvt
.GetType();
1740 if ( EVENT_KEYINPUT
== nType
&& rNEvt
.GetKeyEvent() )
1742 const KeyCode
& rKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
1743 sal_uInt16 nCode
= rKeyCode
.GetCode();
1745 if ( !rKeyCode
.GetModifier() &&
1746 KEY_BACKSPACE
== nCode
&& !_pImp
->_pEdFileName
->HasChildPathFocus() )
1750 if ( !nRet
&& _pImp
->_pBtnUp
->IsEnabled() )
1757 return nRet
? nRet
: ModalDialog::Notify( rNEvt
);
1760 //*****************************************************************************
1762 long SvtFileDialog::OK()
1767 //*****************************************************************************
1769 class SvtDefModalDialogParent_Impl
1775 SvtDefModalDialogParent_Impl( Window
*pNew
) :
1776 _pOld( Application::GetDefDialogParent() )
1777 { Application::SetDefDialogParent( pNew
); }
1779 ~SvtDefModalDialogParent_Impl() { Application::SetDefDialogParent( _pOld
); }
1782 //*****************************************************************************
1784 //---------------------------------------------------------------------
1785 void SvtFileDialog::updateListboxLabelSizes()
1787 sal_Int16 nLineControlId
[5] = {
1788 LISTBOX_VERSION
, LISTBOX_TEMPLATE
, LISTBOX_IMAGE_TEMPLATE
, LISTBOX_FILTER
, EDIT_FILEURL
1791 // determine the maximum width needed for the listbox labels
1793 for ( sal_Int32 i
=0; i
<5; ++i
)
1795 FixedText
* pLabel
= static_cast< FixedText
* >( getControl( nLineControlId
[i
], sal_True
) );
1798 nMaxWidth
= ::std::max( pLabel
->GetTextWidth( pLabel
->GetText() ), nMaxWidth
);
1801 // ensure that all labels are wide enough
1802 for ( sal_Int32 i
=0; i
<5; ++i
)
1804 FixedText
* pLabel
= static_cast< FixedText
* >( getControl( nLineControlId
[i
], sal_True
) );
1805 ListBox
* pListbox
= static_cast< ListBox
* >( getControl( nLineControlId
[i
], sal_False
) );
1806 if ( !pLabel
|| !pListbox
)
1808 Size
aCurrentSize( pLabel
->GetSizePixel() );
1809 if ( aCurrentSize
.Width() >= nMaxWidth
)
1812 long nChange
= nMaxWidth
- aCurrentSize
.Width();
1813 pLabel
->SetSizePixel( Size( nMaxWidth
, aCurrentSize
.Height() ) );
1815 aCurrentSize
= pListbox
->GetSizePixel();
1816 pListbox
->SetSizePixel( Size( aCurrentSize
.Width() - nChange
, aCurrentSize
.Height() ) );
1817 lcl_MoveControl( pListbox
, nChange
, 0 );
1824 bool implIsInvalid( const String
& rURL
)
1826 SmartContent
aContent( rURL
);
1827 aContent
.enableOwnInteractionHandler( ::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST
);
1828 aContent
.isFolder(); // do this _before_ asking isInvalid! Otherwise result might be wrong.
1829 return aContent
.isInvalid();
1834 //---------------------------------------------------------------------
1835 String
SvtFileDialog::implGetInitialURL( const String
& _rPath
, const String
& _rFallback
)
1837 // an URL parser for the fallback
1838 INetURLObject aURLParser
;
1841 bool bWasAbsolute
= sal_False
;
1842 aURLParser
= aURLParser
.smartRel2Abs( _rPath
, bWasAbsolute
);
1844 // is it a valid folder?
1845 m_aContent
.bindTo( aURLParser
.GetMainURL( INetURLObject::NO_DECODE
) );
1846 sal_Bool bIsFolder
= m_aContent
.isFolder( ); // do this _before_ asking isInvalid!
1847 sal_Bool bIsInvalid
= m_aContent
.isInvalid();
1849 if ( bIsInvalid
&& m_bHasFilename
&& !aURLParser
.hasFinalSlash() )
1850 { // check if the parent folder exists
1851 INetURLObject
aParent( aURLParser
);
1852 aParent
.removeSegment( );
1853 aParent
.setFinalSlash( );
1854 bIsInvalid
= implIsInvalid( aParent
.GetMainURL( INetURLObject::NO_DECODE
) );
1859 INetURLObject
aFallback( _rFallback
);
1860 bIsInvalid
= implIsInvalid( aFallback
.GetMainURL( INetURLObject::NO_DECODE
) );
1863 aURLParser
= aFallback
;
1868 INetURLObject
aParent( aURLParser
);
1869 while ( bIsInvalid
&& aParent
.removeSegment() )
1871 aParent
.setFinalSlash( );
1872 bIsInvalid
= implIsInvalid( aParent
.GetMainURL( INetURLObject::NO_DECODE
) );
1876 aURLParser
= aParent
;
1879 if ( !bIsInvalid
&& bIsFolder
)
1881 aURLParser
.setFinalSlash();
1883 return aURLParser
.GetMainURL( INetURLObject::NO_DECODE
);
1886 //---------------------------------------------------------------------
1887 short SvtFileDialog::Execute()
1889 if ( !PrepareExecute() )
1893 _bIsInExecute
= sal_True
;
1894 short nResult
= ModalDialog::Execute();
1895 _bIsInExecute
= sal_False
;
1897 DBG_ASSERT( !m_pCurrentAsyncAction
.is(), "SvtFilePicker::Execute: still running an async action!" );
1898 // the dialog should not be cancellable while an async action is running - first, the action
1899 // needs to be cancelled
1901 // remember last directory
1902 if ( RET_OK
== nResult
)
1904 INetURLObject
aURL( _aPath
);
1905 if ( aURL
.GetProtocol() == INET_PROT_FILE
)
1907 // remember the selected directory only for file URLs not for virtual folders
1908 sal_Int32 nLevel
= aURL
.getSegmentCount();
1909 sal_Bool bDir
= m_aContent
.isFolder( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
1910 if ( nLevel
> 1 && ( FILEDLG_TYPE_FILEDLG
== _pImp
->_eDlgType
|| !bDir
) )
1911 aURL
.removeSegment();
1918 //---------------------------------------------------------------------
1919 void SvtFileDialog::StartExecuteModal( const Link
& rEndDialogHdl
)
1923 // start of the dialog
1924 ModalDialog::StartExecuteModal( rEndDialogHdl
);
1927 //-----------------------------------------------------------------------------
1928 void SvtFileDialog::onAsyncOperationStarted()
1930 EnableUI( sal_False
);
1931 // the cancel button must be always enabled
1932 _pImp
->_pBtnCancel
->Enable( sal_True
);
1933 _pImp
->_pBtnCancel
->GrabFocus();
1936 //-----------------------------------------------------------------------------
1937 void SvtFileDialog::onAsyncOperationFinished()
1939 EnableUI( sal_True
);
1940 m_pCurrentAsyncAction
= NULL
;
1941 if ( !m_bInExecuteAsync
)
1942 _pImp
->_pEdFileName
->GrabFocus();
1943 // (if m_bInExecuteAsync is true, then the operation was finished within the minium wait time,
1944 // and to the user, the operation appears to be synchronous)
1947 //-----------------------------------------------------------------------------
1948 void SvtFileDialog::RemovablePlaceSelected(bool enable
)
1950 _pImp
->_pPlaces
->SetDelEnabled( enable
);
1953 //-------------------------------------------------------------------------
1954 void SvtFileDialog::displayIOException( const String
& _rURL
, IOErrorCode _eCode
)
1958 // create make a human-readable string from the URL
1959 OUString
sDisplayPath( _rURL
);
1960 ::utl::LocalFileHelper::ConvertURLToSystemPath( _rURL
, sDisplayPath
);
1962 // build an own exception which tells "access denied"
1963 InteractiveAugmentedIOException aException
;
1964 aException
.Arguments
.realloc( 2 );
1965 aException
.Arguments
[ 0 ] <<= sDisplayPath
;
1966 aException
.Arguments
[ 1 ] <<= PropertyValue(
1968 -1, aException
.Arguments
[ 0 ], PropertyState_DIRECT_VALUE
1970 // (formerly, it was sufficient to put the URL first parameter. Nowadays,
1971 // the services expects the URL in a PropertyValue named "Uri" ...)
1972 aException
.Code
= _eCode
;
1973 aException
.Classification
= InteractionClassification_ERROR
;
1975 // let and interaction handler handle this exception
1976 ::comphelper::OInteractionRequest
* pRequest
= NULL
;
1977 Reference
< ::com::sun::star::task::XInteractionRequest
> xRequest
= pRequest
=
1978 new ::comphelper::OInteractionRequest( makeAny( aException
) );
1979 pRequest
->addContinuation( new ::comphelper::OInteractionAbort( ) );
1981 Reference
< XInteractionHandler2
> xHandler(
1982 InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), 0 ) );
1983 xHandler
->handle( xRequest
);
1985 catch( const Exception
& )
1987 OSL_FAIL( "iodlg::displayIOException: caught an exception!" );
1991 //-----------------------------------------------------------------------------
1992 void SvtFileDialog::EnableUI( sal_Bool _bEnable
)
1998 for ( ::std::set
< Control
* >::iterator aLoop
= m_aDisabledControls
.begin();
1999 aLoop
!= m_aDisabledControls
.end();
2003 (*aLoop
)->Enable( sal_False
);
2008 //-----------------------------------------------------------------------------
2009 void SvtFileDialog::EnableControl( Control
* _pControl
, sal_Bool _bEnable
)
2013 SAL_WARN( "fpicker.office", "SvtFileDialog::EnableControl: invalid control!" );
2017 _pControl
->Enable( _bEnable
);
2021 ::std::set
< Control
* >::iterator aPos
= m_aDisabledControls
.find( _pControl
);
2022 if ( m_aDisabledControls
.end() != aPos
)
2023 m_aDisabledControls
.erase( aPos
);
2026 m_aDisabledControls
.insert( _pControl
);
2029 //----------------------------------------------------------------------------
2031 short SvtFileDialog::PrepareExecute()
2034 if ( getEnvironmentValue( "WorkDirMustContainRemovableMedia", aEnvValue
) && aEnvValue
== "1" )
2038 INetURLObject
aStdDir( GetStandardDir() );
2039 ::ucbhelper::Content
aCnt( OUString( aStdDir
.GetMainURL(
2040 INetURLObject::NO_DECODE
) ),
2041 Reference
< XCommandEnvironment
>(),
2042 comphelper::getProcessComponentContext() );
2043 Sequence
< OUString
> aProps(2);
2044 aProps
[0] = OUString( "IsVolume" );
2045 aProps
[1] = OUString( "IsRemoveable" );
2047 Reference
< XResultSet
> xResultSet
2048 = aCnt
.createCursor( aProps
, ::ucbhelper::INCLUDE_FOLDERS_ONLY
);
2049 if ( xResultSet
.is() )
2051 Reference
< XRow
> xRow( xResultSet
, UNO_QUERY
);
2054 if ( !xResultSet
->next() )
2066 ErrorBox
aBox( this, WB_OK
, SvtResId( STR_SVT_NOREMOVABLEDEVICE
) );
2072 catch ( ContentCreationException
const & )
2075 catch ( CommandAbortedException
const & )
2080 if ( ( _pImp
->_nStyle
& WB_SAVEAS
) && m_bHasFilename
)
2081 // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2082 // - finally we're going to save that file, aren't we?
2083 m_aContent
.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST
);
2085 m_aContent
.enableDefaultInteractionHandler();
2087 // possibly just a filename without a path
2088 String aFileNameOnly
;
2089 if( _aPath
.Len() && (_pImp
->_eMode
== FILEDLG_MODE_SAVE
)
2090 && (_aPath
.Search(':') == STRING_NOTFOUND
)
2091 && (_aPath
.Search('\\') == STRING_NOTFOUND
)
2092 && (_aPath
.Search('/') == STRING_NOTFOUND
))
2094 aFileNameOnly
= _aPath
;
2098 // no starting path specified?
2099 if ( !_aPath
.Len() )
2101 // then use the standard directory
2102 _aPath
= lcl_ensureFinalSlash( _pImp
->GetStandardDir() );
2104 // attach given filename to path
2105 if ( aFileNameOnly
.Len() )
2106 _aPath
+= aFileNameOnly
;
2109 //.....................................................................
2110 _aPath
= implGetInitialURL( _aPath
, GetStandardDir() );
2112 if ( _pImp
->_nStyle
& WB_SAVEAS
&& !m_bHasFilename
)
2113 // when doing a save-as, we do not want the handler to handle "this file does not exist" messages
2114 // - finally we're going to save that file, aren't we?
2115 m_aContent
.enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::E_DOESNOTEXIST
);
2117 // if applicable show filter
2118 _pImp
->InitFilterList();
2120 // set up initial filter
2121 sal_uInt16 nFilterCount
= GetFilterCount();
2122 OUString aAll
= SvtResId( STR_FILTERNAME_ALL
).toString();
2123 sal_Bool bHasAll
= _pImp
->HasFilterListEntry( aAll
);
2124 if ( _pImp
->GetCurFilter() || nFilterCount
== 1 || ( nFilterCount
== 2 && bHasAll
) )
2126 // if applicable set the only filter or the only filter that
2127 // does not refer to all files, as the current one
2128 if ( !_pImp
->GetCurFilter() )
2130 sal_uInt16 nPos
= 0;
2131 if ( 2 == nFilterCount
&& bHasAll
)
2133 nPos
= nFilterCount
;
2136 if ( aAll
!= OUString( GetFilterName( nPos
) ) )
2140 SvtFileDialogFilter_Impl
* pNewCurFilter
= &(*_pImp
->_pFilter
)[ nPos
];
2141 DBG_ASSERT( pNewCurFilter
, "SvtFileDialog::Execute: invalid filter pos!" );
2142 _pImp
->SetCurFilter( pNewCurFilter
, pNewCurFilter
->GetName() );
2146 _pImp
->SelectFilterListEntry( _pImp
->GetCurFilter()->GetName() );
2147 SetDefaultExt( _pImp
->GetCurFilter()->GetExtension() );
2148 sal_uInt16 nSepPos
= GetDefaultExt().Search( FILEDIALOG_DEF_EXTSEP
);
2149 if ( nSepPos
!= STRING_NOTFOUND
)
2150 EraseDefaultExt( nSepPos
);
2154 // if applicable set respectively create filter for all files
2157 SvtFileDialogFilter_Impl
* pAllFilter
= implAddFilter( aAll
, OUString(FILEDIALOG_FILTER_ALL
) );
2158 _pImp
->InsertFilterListEntry( pAllFilter
);
2159 _pImp
->SetCurFilter( pAllFilter
, aAll
);
2161 _pImp
->SelectFilterListEntry( aAll
);
2164 _pImp
->_pDefaultFilter
= _pImp
->GetCurFilter();
2166 // if applicable isolate filter
2169 if ( !IsolateFilterFromPath_Impl( _aPath
, aFilter
) )
2172 sal_uInt16 nNewFilterFlags
= adjustFilter( aFilter
);
2173 if ( nNewFilterFlags
& ( FLT_NONEMPTY
| FLT_USERFILTER
) )
2175 _pImp
->_pEdFileName
->SetText( aFilter
);
2178 // create and show instance for set path
2179 INetURLObject
aFolderURL( _aPath
);
2180 String
aFileName( aFolderURL
.getName( INetURLObject::LAST_SEGMENT
, false ) );
2181 xub_StrLen nFileNameLen
= aFileName
.Len();
2182 bool bFileToSelect
= nFileNameLen
!= 0;
2183 if ( bFileToSelect
&& aFileName
.GetChar( nFileNameLen
- 1 ) != INET_PATH_TOKEN
)
2185 _pImp
->_pEdFileName
->SetText( GET_DECODED_NAME( aFolderURL
) );
2186 aFolderURL
.removeSegment();
2189 INetURLObject aObj
= aFolderURL
;
2190 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
2192 // set folder as current directory
2193 aObj
.setFinalSlash();
2196 UpdateControls( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2198 // Somebody might want to enable some controls acording to the current filter
2201 ViewHdl_Impl( this, NULL
);
2202 OpenURL_Impl( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2206 SvtDefModalDialogParent_Impl
aDefParent( this );
2208 // if applicable read and set size from ini
2214 //-----------------------------------------------------------------------------
2215 void SvtFileDialog::executeAsync( ::svt::AsyncPickerAction::Action _eAction
,
2216 const String
& _rURL
, const String
& _rFilter
)
2218 DBG_ASSERT( !m_pCurrentAsyncAction
.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );
2220 m_pCurrentAsyncAction
= new AsyncPickerAction( this, _pFileView
, _eAction
);
2222 bool bReallyAsync
= true;
2223 m_aConfiguration
.getNodeValue( OUString( "FillAsynchronously" ) ) >>= bReallyAsync
;
2225 sal_Int32 nMinTimeout
= 0;
2226 m_aConfiguration
.getNodeValue( OUString( "Timeout/Min" ) ) >>= nMinTimeout
;
2227 sal_Int32 nMaxTimeout
= 0;
2228 m_aConfiguration
.getNodeValue( OUString( "Timeout/Max" ) ) >>= nMaxTimeout
;
2230 m_bInExecuteAsync
= true;
2231 m_pCurrentAsyncAction
->execute( _rURL
, _rFilter
, bReallyAsync
? nMinTimeout
: -1, nMaxTimeout
, GetBlackList() );
2232 m_bInExecuteAsync
= false;
2235 //*****************************************************************************
2237 void SvtFileDialog::FileSelect()
2239 if ( _pFileNotifier
)
2240 _pFileNotifier
->notify( FILE_SELECTION_CHANGED
, 0 );
2243 //*****************************************************************************
2245 void SvtFileDialog::FilterSelect()
2247 if ( _pFileNotifier
)
2248 _pFileNotifier
->notify( CTRL_STATE_CHANGED
,
2252 //*****************************************************************************
2254 void SvtFileDialog::SetStandardDir( const String
& rStdDir
)
2258 This method sets the path for the default button.
2262 INetURLObject
aObj( rStdDir
);
2263 DBG_ASSERT( aObj
.GetProtocol() != INET_PROT_NOT_VALID
, "Invalid protocol!" );
2264 aObj
.setFinalSlash();
2265 _pImp
->SetStandardDir( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2268 void SvtFileDialog::SetBlackList( const ::com::sun::star::uno::Sequence
< OUString
>& rBlackList
)
2270 _pImp
->SetBlackList( rBlackList
);
2273 //*****************************************************************************
2275 const ::com::sun::star::uno::Sequence
< OUString
>& SvtFileDialog::GetBlackList() const
2277 return _pImp
->GetBlackList();
2279 //*****************************************************************************
2281 const String
& SvtFileDialog::GetStandardDir() const
2285 This method returns the standard path.
2289 return _pImp
->GetStandardDir();
2292 //*****************************************************************************
2294 void SvtFileDialog::PrevLevel_Impl()
2296 _pFileView
->EndInplaceEditing( false );
2299 executeAsync( AsyncPickerAction::ePrevLevel
, sDummy
, sDummy
);
2302 //*****************************************************************************
2304 void SvtFileDialog::OpenURL_Impl( const String
& _rURL
)
2306 _pFileView
->EndInplaceEditing( false );
2308 executeAsync( AsyncPickerAction::eOpenURL
, _rURL
, getMostCurrentFilter( _pImp
) );
2311 //*****************************************************************************
2312 SvtFileDialogFilter_Impl
* SvtFileDialog::implAddFilter( const String
& _rFilter
, const String
& _rType
)
2314 SvtFileDialogFilter_Impl
* pNewFilter
= new SvtFileDialogFilter_Impl( _rFilter
, _rType
);
2315 _pImp
->_pFilter
->push_front( pNewFilter
);
2317 if ( !_pImp
->GetCurFilter() )
2318 _pImp
->SetCurFilter( pNewFilter
, _rFilter
);
2323 //*****************************************************************************
2325 void SvtFileDialog::AddFilter( const String
& _rFilter
, const String
& _rType
)
2327 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2328 implAddFilter ( _rFilter
, _rType
);
2331 //*****************************************************************************
2332 void SvtFileDialog::AddFilterGroup( const String
& _rFilter
, const Sequence
< StringPair
>& _rFilters
)
2334 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::AddFilter: currently executing!" );
2336 implAddFilter( _rFilter
, String() );
2337 const StringPair
* pSubFilters
= _rFilters
.getConstArray();
2338 const StringPair
* pSubFiltersEnd
= pSubFilters
+ _rFilters
.getLength();
2339 for ( ; pSubFilters
!= pSubFiltersEnd
; ++pSubFilters
)
2340 implAddFilter( pSubFilters
->First
, pSubFilters
->Second
);
2343 //-----------------------------------------------------------------------------
2344 void SvtFileDialog::SetCurFilter( const String
& rFilter
)
2346 DBG_ASSERT( !IsInExecute(), "SvtFileDialog::SetCurFilter: currently executing!" );
2348 // look for corresponding filter
2349 sal_uInt16 nPos
= _pImp
->_pFilter
->size();
2353 SvtFileDialogFilter_Impl
* pFilter
= &(*_pImp
->_pFilter
)[ nPos
];
2354 if ( pFilter
->GetName() == rFilter
)
2356 _pImp
->SetCurFilter( pFilter
, rFilter
);
2362 //*****************************************************************************
2364 String
SvtFileDialog::GetCurFilter() const
2368 const SvtFileDialogFilter_Impl
* pCurrentFilter
= _pImp
->GetCurFilter();
2369 if ( pCurrentFilter
)
2370 aFilter
= pCurrentFilter
->GetName();
2375 String
SvtFileDialog::getCurFilter( ) const
2377 return GetCurFilter();
2380 //*****************************************************************************
2382 sal_uInt16
SvtFileDialog::GetFilterCount() const
2384 return _pImp
->_pFilter
->size();
2387 //*****************************************************************************
2389 const String
& SvtFileDialog::GetFilterName( sal_uInt16 nPos
) const
2391 DBG_ASSERT( nPos
< GetFilterCount(), "invalid index" );
2392 return (*_pImp
->_pFilter
)[ nPos
].GetName();
2395 //*****************************************************************************
2397 void SvtFileDialog::InitSize()
2399 if ( ! _pImp
->_aIniKey
.Len() )
2402 Size aDlgSize
= GetResizeOutputSizePixel();
2403 SetMinOutputSizePixel( aDlgSize
);
2405 if ( !_pImp
->_nFixDeltaHeight
)
2407 // calculate and save fixsize
2408 long nBoxH
= _pFileView
->GetSizePixel().Height();
2409 long nH
= GetSizePixel().Height();
2410 _pImp
->_nFixDeltaHeight
= nH
- nBoxH
;
2413 // initialize from config
2414 SvtViewOptions
aDlgOpt( E_DIALOG
, _pImp
->_aIniKey
);
2416 if ( aDlgOpt
.Exists() )
2418 SetWindowState(OUStringToOString(aDlgOpt
.GetWindowState(), osl_getThreadTextEncoding()));
2420 Any aUserData
= aDlgOpt
.GetUserItem( OUString( "UserData" ));
2422 if ( aUserData
>>= sCfgStr
)
2423 _pFileView
->SetConfigString( String( sCfgStr
) );
2427 //*****************************************************************************
2429 std::vector
<OUString
> SvtFileDialog::GetPathList() const
2431 std::vector
<OUString
> aList
;
2432 sal_uLong nCount
= _pFileView
->GetSelectionCount();
2433 SvTreeListEntry
* pEntry
= nCount
? _pFileView
->FirstSelected() : NULL
;
2437 if ( !_pImp
->_pEdFileName
->GetText().isEmpty() && _bIsInExecute
)
2438 aList
.push_back(_pImp
->_pEdFileName
->GetURL());
2440 aList
.push_back(_aPath
);
2446 aList
.push_back(_pFileView
->GetURL(pEntry
));
2447 pEntry
= _pFileView
->NextSelected( pEntry
);
2454 //*****************************************************************************
2456 void SvtFileDialog::implArrangeControls()
2458 // this is the list of controls in the order they should be tabbed
2459 // from topleft to bottomright
2460 // pb: #136070# new order so all LabeledBy relations are correct now
2461 Control
* pControls
[] =
2463 _pImp
->_pEdCurrentPath
, _pImp
->_pBtnConnectToServer
,
2464 _pImp
->_pBtnUp
, _pImp
->_pBtnNewFolder
, // image buttons
2465 _pImp
->_pPlaces
, // list of places
2466 _pFileView
, // the file view
2467 _pImp
->_pFtFileName
, _pImp
->_pEdFileName
,
2468 _pImp
->_pFtFileVersion
, _pImp
->_pLbFileVersion
,
2469 _pImp
->_pFtTemplates
, _pImp
->_pLbTemplates
,
2470 _pImp
->_pFtImageTemplates
, _pImp
->_pLbImageTemplates
,
2471 _pImp
->_pFtFileType
, _pImp
->GetFilterListControl(), // edit fields/list boxes
2472 _pImp
->_pCbPassword
, _pImp
->_pCbAutoExtension
, _pImp
->_pCbOptions
, // checkboxes
2473 _pCbReadOnly
, _pCbLinkBox
, _pCbPreviewBox
, _pCbSelection
, _pPbPlay
, // check boxes (continued)
2474 _pImp
->_pBtnFileOpen
, _pImp
->_pBtnCancel
, _pImp
->_pBtnHelp
// buttons
2476 // (including the FixedTexts is important - not for tabbing order (they're irrelevant there),
2477 // but for working keyboard shortcuts)
2480 // loop through all these controls and adjust the z-order
2481 Window
* pPreviousWin
= NULL
;
2482 Control
** pCurrent
= pControls
;
2483 for ( sal_Int32 i
= 0; i
< sal_Int32(sizeof( pControls
) / sizeof( pControls
[ 0 ] )); ++i
, ++pCurrent
)
2486 // this control is not available in the current operation mode -> skip
2490 (*pCurrent
)->SetZOrder( pPreviousWin
, WINDOW_ZORDER_BEHIND
);
2492 (*pCurrent
)->SetZOrder( NULL
, WINDOW_ZORDER_FIRST
);
2494 pPreviousWin
= *pCurrent
;
2497 // FileName edit not the first control but it should have the focus initially
2498 _pImp
->_pEdFileName
->GrabFocus();
2501 //*****************************************************************************
2503 sal_Bool
SvtFileDialog::IsolateFilterFromPath_Impl( String
& rPath
, String
& rFilter
)
2506 String aReversePath
= comphelper::string::reverseString(rPath
);
2507 sal_uInt16 nQuestionMarkPos
= rPath
.Search( '?' );
2509 if ( nQuestionMarkPos
!= STRING_NOTFOUND
)
2511 // use question mark as wildcard only for files
2512 INetProtocol eProt
= INetURLObject::CompareProtocolScheme( rPath
);
2514 if ( INET_PROT_NOT_VALID
!= eProt
&& INET_PROT_FILE
!= eProt
)
2515 nQuestionMarkPos
= STRING_NOTFOUND
;
2517 sal_uInt16 nWildCardPos
= std::min( rPath
.Search( FILEDIALOG_DEF_WILDCARD
), nQuestionMarkPos
);
2520 if ( nWildCardPos
!= STRING_NOTFOUND
)
2522 sal_uInt16 nPathTokenPos
= aReversePath
.Search( INET_PATH_TOKEN
);
2524 if ( nPathTokenPos
== STRING_NOTFOUND
)
2534 nPathTokenPos
= aReversePath
.Search( aDelim
);
2536 if ( nPathTokenPos
== STRING_NOTFOUND
)
2538 nPathTokenPos
= aReversePath
.Search( ':' );
2544 if ( nPathTokenPos
!= STRING_NOTFOUND
)
2546 if ( nPathTokenPos
< (rPath
.Len() - nWildCardPos
- 1) )
2548 ErrorHandler::HandleError( ERRCODE_SFX_INVALIDSYNTAX
);
2553 rFilter
= aReversePath
;
2554 rFilter
.Erase( nPathTokenPos
);
2555 rFilter
= comphelper::string::reverseString(rFilter
);
2558 rPath
= aReversePath
;
2559 rPath
.Erase( 0, nPathTokenPos
);
2560 rPath
= comphelper::string::reverseString(rPath
);
2572 //-----------------------------------------------------------------------------
2573 void SvtFileDialog::implUpdateImages( )
2575 m_aImages
= ImageList( SvtResId( RID_FILEPICKER_IMAGES
) );
2577 // set the appropriate images on the buttons
2578 if ( _pImp
->_pBtnUp
)
2579 _pImp
->_pBtnUp
->SetModeImage( GetButtonImage( IMG_FILEDLG_BTN_UP
) );
2581 if ( _pImp
->_pBtnNewFolder
)
2582 _pImp
->_pBtnNewFolder
->SetModeImage( GetButtonImage( IMG_FILEDLG_CREATEFOLDER
) );
2585 //-----------------------------------------------------------------------------
2586 void SvtFileDialog::DataChanged( const DataChangedEvent
& _rDCEvt
)
2588 if ( DATACHANGED_SETTINGS
== _rDCEvt
.GetType() )
2589 implUpdateImages( );
2591 ModalDialog::DataChanged( _rDCEvt
);
2594 //-----------------------------------------------------------------------------
2595 void SvtFileDialog::Resize()
2600 Size aDlgSize
= GetResizeOutputSizePixel();
2601 Size aOldSize
= _pImp
->_aDlgSize
;
2602 _pImp
->_aDlgSize
= aDlgSize
;
2603 long nWinDeltaW
= 0;
2606 _pPrevWin
->GetPosPixel().X() > _pFileView
->GetPosPixel().X() )
2608 nWinDeltaW
= _pPrevWin
->GetOutputSizePixel().Width() + _pImp
->_a6Size
.Width();
2611 Size aNewSize
= _pFileView
->GetSizePixel();
2612 Point
aBoxPos( _pFileView
->GetPosPixel() );
2613 long nDeltaY
= aNewSize
.Height();
2614 long nDeltaX
= aNewSize
.Width();
2615 aNewSize
.Height() = aDlgSize
.Height() - _pImp
->_nFixDeltaHeight
;
2616 aNewSize
.Width() = aDlgSize
.Width() - aBoxPos
.X() - _pImp
->_a6Size
.Width() - nWinDeltaW
;
2617 if ( aOldSize
.Height() )
2618 nDeltaY
= _pImp
->_aDlgSize
.Height() - aOldSize
.Height();
2620 nDeltaY
= aNewSize
.Height() - nDeltaY
;
2621 nDeltaX
= aNewSize
.Width() - nDeltaX
;
2624 nWinDeltaW
= nDeltaX
* 2 / 3;
2625 aNewSize
.Width() -= nWinDeltaW
;
2626 nDeltaX
-= nWinDeltaW
;
2628 _pFileView
->SetSizePixel( aNewSize
);
2630 // Resize the Splitter to fit the height
2631 Size splitterNewSize
= _pSplitter
->GetSizePixel( );
2632 splitterNewSize
.Height() += nDeltaY
;
2633 _pSplitter
->SetSizePixel( splitterNewSize
);
2634 sal_Int32 nMinX
= _pImp
->_pPlaces
->GetPosPixel( ).X( );
2635 sal_Int32 nMaxX
= _pFileView
->GetPosPixel( ).X( ) + _pFileView
->GetSizePixel( ).Width() - nMinX
;
2636 _pSplitter
->SetDragRectPixel( Rectangle( Point( nMinX
, 0 ), Size( nMaxX
, aDlgSize
.Width() ) ) );
2638 // Resize the places list box to fit the height of the FileView
2639 Size
placesNewSize(_pImp
->_pPlaces
->GetSizePixel());
2640 placesNewSize
.Height() += nDeltaY
;
2641 _pImp
->_pPlaces
->SetSizePixel( placesNewSize
);
2643 if ( !nDeltaY
&& !nDeltaX
)
2644 // This resize was only called to show or hide the indicator.
2650 // controls to move vertically
2652 Control
* aMoveControlsVert
[] =
2654 _pImp
->_pFtFileName
, _pImp
->_pEdFileName
, _pImp
->_pFtFileVersion
, _pImp
->_pLbFileVersion
,
2655 _pImp
->_pFtTemplates
, _pImp
->_pLbTemplates
, _pImp
->_pFtImageTemplates
, _pImp
->_pLbImageTemplates
,
2656 _pImp
->_pFtFileType
, _pImp
->GetFilterListControl(), _pCbReadOnly
, _pCbLinkBox
, _pCbPreviewBox
,
2657 _pPbPlay
, _pImp
->_pCbPassword
, _pImp
->_pCbAutoExtension
, _pImp
->_pCbOptions
, _pCbSelection
2659 Control
** ppMoveControls
= aMoveControlsVert
;
2660 Control
** ppMoveControlsEnd
= ppMoveControls
+ sizeof( aMoveControlsVert
) / sizeof( aMoveControlsVert
[0] );
2661 for ( ; ppMoveControls
!= ppMoveControlsEnd
; ++ppMoveControls
)
2662 lcl_MoveControl( *ppMoveControls
, 0, nDeltaY
);
2665 // controls to move vertically and horizontally
2667 Control
* aMoveControlsBoth
[] =
2669 _pImp
->_pBtnFileOpen
, _pImp
->_pBtnCancel
, _pImp
->_pBtnHelp
2671 Control
** ppMoveControls
= aMoveControlsBoth
;
2672 Control
** ppMoveControlsEnd
= ppMoveControls
+ sizeof( aMoveControlsBoth
) / sizeof( aMoveControlsBoth
[0] );
2673 for ( ; ppMoveControls
!= ppMoveControlsEnd
; ++ppMoveControls
)
2674 lcl_MoveControl( *ppMoveControls
, nDeltaX
, nDeltaY
);
2677 // controls to move horizontally
2679 Control
* aMoveControlsHor
[] =
2681 _pImp
->_pBtnConnectToServer
,
2682 _pImp
->_pBtnUp
, _pImp
->_pBtnNewFolder
2684 Control
** ppMoveControls
= aMoveControlsHor
;
2685 Control
** ppMoveControlsEnd
= ppMoveControls
+ sizeof( aMoveControlsHor
) / sizeof( aMoveControlsHor
[0] );
2686 for ( ; ppMoveControls
!= ppMoveControlsEnd
; ++ppMoveControls
)
2687 lcl_MoveControl( *ppMoveControls
, nDeltaX
, 0 );
2693 Control
* aSizeControls
[] =
2695 _pImp
->_pEdFileName
, _pImp
->_pLbFileVersion
, _pImp
->_pLbTemplates
, _pImp
->_pLbImageTemplates
,
2696 _pImp
->GetFilterListControl(), _pImp
->_pEdCurrentPath
,
2698 sal_Int32 nSizeControls
= sizeof( aSizeControls
) / sizeof( aSizeControls
[0] );
2699 Control
** ppSizeControls
= aSizeControls
;
2700 for ( sal_Int32 j
=0; j
<nSizeControls
; ++j
, ++ppSizeControls
)
2702 if ( *ppSizeControls
)
2704 aNewSize
= (*ppSizeControls
)->GetSizePixel();
2705 aNewSize
.Width() += nDeltaX
;
2706 (*ppSizeControls
)->SetSizePixel( aNewSize
);
2711 // align additional controls
2713 _pPrevWin
->GetPosPixel().X() > _pFileView
->GetPosPixel().X() )
2715 // special alignment for controls of the type window
2716 // also adjust the size
2717 Point aNewPos
= _pPrevWin
->GetPosPixel();
2718 aNewPos
.X() += nDeltaX
;
2719 _pPrevWin
->SetPosPixel( aNewPos
);
2720 _pPrevBmp
->SetPosPixel( aNewPos
);
2721 aNewSize
= _pPrevWin
->GetOutputSizePixel();
2722 aNewSize
.Width() += nWinDeltaW
;
2723 aNewSize
.Height() += nDeltaY
;
2724 if ( !aOldSize
.Height() )
2725 aNewSize
.Height() -= ( _pImp
->_a6Size
.Height() / 2 );
2726 _pPrevWin
->SetOutputSizePixel( aNewSize
);
2727 _pPrevBmp
->SetOutputSizePixel( aNewSize
);
2728 _pPrevBmp
->Invalidate();
2731 if ( _pFileNotifier
)
2732 _pFileNotifier
->notify( DIALOG_SIZE_CHANGED
, 0 );
2735 //-----------------------------------------------------------------------------
2736 Control
* SvtFileDialog::getControl( sal_Int16 _nControlId
, sal_Bool _bLabelControl
) const
2738 Control
* pReturn
= NULL
;
2740 switch ( _nControlId
)
2742 case CONTROL_FILEVIEW
:
2743 pReturn
= _bLabelControl
? NULL
: static_cast< Control
* >( _pFileView
);
2747 pReturn
= _bLabelControl
2748 ? static_cast< Control
* >( _pImp
->_pFtFileName
)
2749 : static_cast< Control
* >( _pImp
->_pEdFileName
);
2752 case EDIT_FILEURL_LABEL
:
2753 pReturn
= static_cast< Control
* >( _pImp
->_pFtFileName
);
2756 case CHECKBOX_AUTOEXTENSION
:
2757 pReturn
= _pImp
->_pCbAutoExtension
;
2760 case CHECKBOX_PASSWORD
:
2761 pReturn
= _pImp
->_pCbPassword
;
2764 case CHECKBOX_FILTEROPTIONS
:
2765 pReturn
= _pImp
->_pCbOptions
;
2768 case CHECKBOX_READONLY
:
2769 pReturn
= _pCbReadOnly
;
2773 pReturn
= _pCbLinkBox
;
2776 case CHECKBOX_PREVIEW
:
2777 pReturn
= _pCbPreviewBox
;
2780 case CHECKBOX_SELECTION
:
2781 pReturn
= _pCbSelection
;
2784 case LISTBOX_FILTER
:
2785 pReturn
= _bLabelControl
? _pImp
->_pFtFileType
: _pImp
->GetFilterListControl();
2788 case LISTBOX_FILTER_LABEL
:
2789 pReturn
= _pImp
->_pFtFileType
;
2792 case FIXEDTEXT_CURRENTFOLDER
:
2793 pReturn
= _pImp
->_pEdCurrentPath
;
2796 case LISTBOX_VERSION
:
2797 pReturn
= _bLabelControl
2798 ? static_cast< Control
* >( _pImp
->_pFtFileVersion
)
2799 : static_cast< Control
* >( _pImp
->_pLbFileVersion
);
2802 case LISTBOX_TEMPLATE
:
2803 pReturn
= _bLabelControl
2804 ? static_cast< Control
* >( _pImp
->_pFtTemplates
)
2805 : static_cast< Control
* >( _pImp
->_pLbTemplates
);
2808 case LISTBOX_IMAGE_TEMPLATE
:
2809 pReturn
= _bLabelControl
2810 ? static_cast< Control
* >( _pImp
->_pFtImageTemplates
)
2811 : static_cast< Control
* >( _pImp
->_pLbImageTemplates
);
2814 case LISTBOX_VERSION_LABEL
:
2815 pReturn
= _pImp
->_pFtFileVersion
;
2818 case LISTBOX_TEMPLATE_LABEL
:
2819 pReturn
= _pImp
->_pFtTemplates
;
2822 case LISTBOX_IMAGE_TEMPLATE_LABEL
:
2823 pReturn
= _pImp
->_pFtImageTemplates
;
2827 pReturn
= _pImp
->_pBtnFileOpen
;
2830 case PUSHBUTTON_CANCEL
:
2831 pReturn
= _pImp
->_pBtnCancel
;
2834 case PUSHBUTTON_PLAY
:
2838 case PUSHBUTTON_HELP
:
2839 pReturn
= _pImp
->_pBtnHelp
;
2842 case TOOLBOXBUTOON_LEVEL_UP
:
2843 pReturn
= _pImp
->_pBtnUp
;
2846 case TOOLBOXBUTOON_NEW_FOLDER
:
2847 pReturn
= _pImp
->_pBtnNewFolder
;
2850 case LISTBOX_FILTER_SELECTOR
:
2851 // only exists on SalGtkFilePicker
2855 SAL_WARN( "fpicker.office", "SvtFileDialog::getControl: invalid id!" );
2860 // -----------------------------------------------------------------------
2861 void SvtFileDialog::enableControl( sal_Int16 _nControlId
, sal_Bool _bEnable
)
2863 Control
* pControl
= getControl( _nControlId
, sal_False
);
2865 EnableControl( pControl
, _bEnable
);
2866 Control
* pLabel
= getControl( _nControlId
, sal_True
);
2868 EnableControl( pLabel
, _bEnable
);
2871 // -----------------------------------------------------------------------
2872 void SvtFileDialog::AddControls_Impl( )
2874 // create the "insert as link" checkbox, if needed
2875 if ( _nExtraBits
& SFX_EXTRA_INSERTASLINK
)
2877 _pCbLinkBox
= new CheckBox( this );
2878 _pCbLinkBox
->SetText( SvtResId( STR_SVT_FILEPICKER_INSERT_AS_LINK
) );
2879 _pCbLinkBox
->SetHelpId( HID_FILEDLG_LINK_CB
);
2880 AddControl( _pCbLinkBox
);
2881 ReleaseOwnership( _pCbLinkBox
);
2882 _pCbLinkBox
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
2885 // create the "show preview" checkbox ( and the preview window, too ), if needed
2886 if ( _nExtraBits
& SFX_EXTRA_SHOWPREVIEW
)
2888 _pImp
->_aIniKey
= IMPGRF_CONFIGNAME
;
2889 // because the "<All Formats> (*.bmp,*...)" entry is to wide,
2890 // we need to disable the auto width feature of the filter box
2891 _pImp
->DisableFilterBoxAutoWidth();
2894 _pCbPreviewBox
= new CheckBox( this );
2895 _pCbPreviewBox
->SetText( SvtResId( STR_SVT_FILEPICKER_SHOW_PREVIEW
) );
2896 _pCbPreviewBox
->SetHelpId( HID_FILEDLG_PREVIEW_CB
);
2897 AddControl( _pCbPreviewBox
);
2898 ReleaseOwnership( _pCbPreviewBox
);
2899 _pCbPreviewBox
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
2901 // generate preview window just here
2902 _pPrevWin
= new Window( this, WinBits( WB_BORDER
) );
2903 AddControl( _pPrevWin
);
2904 ReleaseOwnership( _pPrevWin
);
2907 _pPrevBmp
= new FixedBitmap( this, WinBits( WB_BORDER
) );
2908 _pPrevBmp
->SetBackground( Wallpaper( Color( COL_WHITE
) ) );
2910 _pPrevBmp
->SetAccessibleName(SvtResId(STR_PREVIEW
));
2913 if ( _nExtraBits
& SFX_EXTRA_AUTOEXTENSION
)
2915 _pImp
->_pCbAutoExtension
= new CheckBox( this, SvtResId( CB_AUTO_EXTENSION
) );
2916 _pImp
->_pCbAutoExtension
->SetText( SvtResId( STR_SVT_FILEPICKER_AUTO_EXTENSION
) );
2917 _pImp
->_pCbAutoExtension
->Check( sal_True
);
2918 AddControl( _pImp
->_pCbAutoExtension
);
2919 ReleaseOwnership( _pImp
->_pCbAutoExtension
);
2920 _pImp
->_pCbAutoExtension
->SetClickHdl( LINK( this, SvtFileDialog
, AutoExtensionHdl_Impl
) );
2923 if ( _nExtraBits
& SFX_EXTRA_FILTEROPTIONS
)
2925 _pImp
->_pCbOptions
= new CheckBox( this, SvtResId( CB_OPTIONS
) );
2926 _pImp
->_pCbOptions
->SetText( SvtResId( STR_SVT_FILEPICKER_FILTER_OPTIONS
) );
2927 AddControl( _pImp
->_pCbOptions
);
2928 ReleaseOwnership( _pImp
->_pCbOptions
);
2929 _pImp
->_pCbOptions
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
2932 if ( _nExtraBits
& SFX_EXTRA_SELECTION
)
2934 _pCbSelection
= new CheckBox( this, SvtResId( CB_OPTIONS
) );
2935 _pCbSelection
->SetText( SvtResId( STR_SVT_FILEPICKER_SELECTION
) );
2936 AddControl( _pCbSelection
);
2937 ReleaseOwnership( _pCbSelection
);
2938 _pCbSelection
->SetClickHdl( LINK( this, SvtFileDialog
, ClickHdl_Impl
) );
2941 if ( _nExtraBits
& SFX_EXTRA_PLAYBUTTON
)
2943 _pPbPlay
= new PushButton( this );
2944 _pPbPlay
->SetText( SvtResId( STR_SVT_FILEPICKER_PLAY
) );
2945 _pPbPlay
->SetHelpId( HID_FILESAVE_DOPLAY
);
2946 AddControl( _pPbPlay
);
2947 ReleaseOwnership( _pPbPlay
);
2948 _pPbPlay
->SetClickHdl( LINK( this, SvtFileDialog
, PlayButtonHdl_Impl
) );
2951 if ( _nExtraBits
& SFX_EXTRA_SHOWVERSIONS
)
2953 _pImp
->_pFtFileVersion
= new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
2954 _pImp
->_pFtFileVersion
->SetText( SvtResId( STR_SVT_FILEPICKER_VERSION
) );
2956 _pImp
->_pLbFileVersion
= new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
2957 _pImp
->_pLbFileVersion
->SetHelpId( HID_FILEOPEN_VERSION
);
2959 else if ( _nExtraBits
& SFX_EXTRA_TEMPLATES
)
2961 _pImp
->_pFtTemplates
= new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
2962 _pImp
->_pFtTemplates
->SetText( SvtResId( STR_SVT_FILEPICKER_TEMPLATES
) );
2964 _pImp
->_pLbTemplates
= new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
2965 _pImp
->_pLbTemplates
->SetHelpId( HID_FILEOPEN_VERSION
);
2966 // This is strange. During the re-factoring during 96930, I discovered that this help id
2967 // is set in the "Templates mode". This was hidden in the previous implementation.
2968 // Shouldn't this be a more meaningfull help id.
2970 else if ( _nExtraBits
& SFX_EXTRA_IMAGE_TEMPLATE
)
2972 _pImp
->_pFtImageTemplates
= new FixedText( this, SvtResId( FT_EXPLORERFILE_SHARED_LISTBOX
) );
2973 _pImp
->_pFtImageTemplates
->SetText( SvtResId( STR_SVT_FILEPICKER_IMAGE_TEMPLATE
) );
2975 _pImp
->_pLbImageTemplates
= new ListBox( this, SvtResId( LB_EXPLORERFILE_SHARED_LISTBOX
) );
2976 _pImp
->_pLbImageTemplates
->SetHelpId( HID_FILEOPEN_IMAGE_TEMPLATE
);
2979 _pImp
->_pPlaces
= new PlacesListBox( this, SVT_RESSTR(STR_PLACES_TITLE
), SvtResId(LB_EXPLORERFILE_PLACES_LISTBOX
) );
2980 _pImp
->_pPlaces
->SetAddHdl( LINK ( this, SvtFileDialog
, AddPlacePressed_Hdl
) );
2981 _pImp
->_pPlaces
->SetDelHdl( LINK ( this, SvtFileDialog
, RemovePlacePressed_Hdl
) );
2983 initDefaultPlaces();
2986 // -----------------------------------------------------------------------
2987 sal_Int32
SvtFileDialog::getTargetColorDepth()
2990 return _pPrevBmp
->GetBitCount();
2995 // -----------------------------------------------------------------------
2996 sal_Int32
SvtFileDialog::getAvailableWidth()
2999 return _pPrevBmp
->GetOutputSizePixel().Width();
3004 // -----------------------------------------------------------------------
3005 sal_Int32
SvtFileDialog::getAvailableHeight()
3008 return _pPrevBmp
->GetOutputSizePixel().Height();
3013 // -----------------------------------------------------------------------
3014 void SvtFileDialog::setImage( sal_Int16
/*aImageFormat*/, const Any
& rImage
)
3016 if ( ! _pPrevBmp
|| ! _pPrevBmp
->IsVisible() )
3019 Sequence
< sal_Int8
> aBmpSequence
;
3021 if ( rImage
>>= aBmpSequence
)
3024 SvMemoryStream
aData( aBmpSequence
.getArray(),
3025 aBmpSequence
.getLength(),
3029 _pPrevBmp
->SetBitmap( aBmp
);
3034 _pPrevBmp
->SetBitmap( aEmpty
);
3038 // -----------------------------------------------------------------------
3039 sal_Bool
SvtFileDialog::setShowState( sal_Bool
/*bShowState*/ )
3041 // #97633 for the system filedialog it's
3042 // useful to make the preview switchable
3043 // because the preview occupies
3044 // half of the size of the file listbox
3045 // which is not the case here,
3046 // so we (TRA/FS) decided not to make
3047 // the preview window switchable because
3048 // else we would have to change the layout
3049 // of the file dialog dynamically
3050 // support for set/getShowState is opionally
3051 // see com::sun::star::ui::dialogs::XFilePreview
3056 // -----------------------------------------------------------------------
3057 String
SvtFileDialog::getCurrentFileText( ) const
3060 if ( _pImp
&& _pImp
->_pEdFileName
)
3061 sReturn
= _pImp
->_pEdFileName
->GetText();
3065 // -----------------------------------------------------------------------
3066 void SvtFileDialog::setCurrentFileText( const String
& _rText
, bool _bSelectAll
)
3068 if ( _pImp
&& _pImp
->_pEdFileName
)
3070 _pImp
->_pEdFileName
->SetText( _rText
);
3072 _pImp
->_pEdFileName
->SetSelection( Selection( 0, _rText
.Len() ) );
3076 // -----------------------------------------------------------------------
3077 sal_Bool
SvtFileDialog::isAutoExtensionEnabled()
3079 return _pImp
->_pCbAutoExtension
&& _pImp
->_pCbAutoExtension
->IsChecked();
3082 // -----------------------------------------------------------------------
3083 sal_Bool
SvtFileDialog::getShowState()
3086 return _pPrevBmp
->IsVisible();
3091 // -----------------------------------------------------------------------
3092 void SvtFileDialog::ReleaseOwnership( Window
* pUserControl
)
3096 This method ensures that the specified element is no longer in possession
3101 ControlChain_Impl
* pElement
= _pUserControls
;
3104 if ( pElement
->_pControl
== pUserControl
)
3106 pElement
->_bHasOwnership
= sal_False
;
3109 pElement
= pElement
->_pNext
;
3113 //***************************************************************************
3115 sal_Bool
SvtFileDialog::AddControl( Window
* pControl
, sal_Bool bNewLine
)
3117 // control already exists
3118 ControlChain_Impl
* pElement
= _pUserControls
;
3121 if ( pElement
->_pControl
== pControl
)
3123 pElement
= pElement
->_pNext
;
3126 // Check if controls have already been added.
3127 Size
aNewControlSize( pControl
->GetOutputSizePixel() );
3128 Size
aDlgSize( GetOutputSizePixel() );
3129 WindowType nType
= pControl
->GetType();
3130 if ( !aNewControlSize
.Height() )
3133 Size
aSize( 0, 10 );
3134 if ( nType
== WINDOW_PUSHBUTTON
)
3136 Size aDefSiz
= LogicToPixel( Size( 50, 14 ), MAP_APPFONT
);
3137 long nTextWidth
= pControl
->GetTextWidth( pControl
->GetText() );
3138 aSize
.Width() = nTextWidth
+ WIDTH_ADDITION
;
3140 // PushButton: Minimum width 50 logical units,
3141 // height always 14 logical units.
3142 if ( aDefSiz
.Width() > aSize
.Width() )
3143 aSize
.Width() = aDefSiz
.Width();
3144 aSize
.Height() = aDefSiz
.Height();
3145 aNewControlSize
= aSize
;
3148 aNewControlSize
= LogicToPixel( aSize
, MAP_APPFONT
);
3149 if ( nType
!= WINDOW_PUSHBUTTON
)
3150 aNewControlSize
.Width() = pControl
->GetTextWidth( pControl
->GetText() ) + WIDTH_ADDITION
;
3151 if ( nType
== WINDOW_CHECKBOX
)
3152 aNewControlSize
.Width() += WIDTH_ADDITION
;
3153 if ( nType
== WINDOW_WINDOW
)
3155 aNewControlSize
.Height() = GetOutputSizePixel().Height() - 18;
3156 aNewControlSize
.Width() = 200;
3157 aDlgSize
.Width() += 210;
3158 SetOutputSizePixel( aDlgSize
);
3160 pControl
->SetOutputSizePixel( aNewControlSize
);
3162 Point aNewControlPos
;
3163 Size
* pNewDlgSize
= NULL
;
3164 sal_Bool bNewRow
= bNewLine
;
3166 if ( nType
== WINDOW_WINDOW
)
3168 aNewControlPos
.X() = aDlgSize
.Width() - 210;
3169 aNewControlPos
.Y() = 8;
3171 else if ( _pUserControls
)
3173 Point
aNewControlRange( _pUserControls
->_pControl
->GetPosPixel() );
3174 long nPrevControlHeight
= _pUserControls
->_pControl
->GetSizePixel().Height();
3176 Point( _pUserControls
->_pControl
->GetOutputSizePixel().Width(), 0 );
3177 aNewControlPos
= aNewControlRange
;
3178 if ( nPrevControlHeight
> aNewControlSize
.Height() )
3180 long nY
= nPrevControlHeight
;
3181 nY
-= aNewControlSize
.Height();
3183 aNewControlPos
.Y() += nY
;
3185 aNewControlPos
+= LogicToPixel( Point( 3, 0 ), MAP_APPFONT
);
3186 aNewControlRange
+= LogicToPixel( Point( 9, 0 ), MAP_APPFONT
);
3187 aNewControlRange
+= Point( aNewControlSize
.Width(), 0 );
3189 // Check if a new row has to be created.
3190 if ( aNewControlRange
.X() > aDlgSize
.Width() )
3195 // Create a new row if there was no usercontrol before.
3199 // Check if a new row has to be created.
3200 Size aBorderSize
= LogicToPixel( Size( 6, 6 ), MAP_APPFONT
);
3201 long nLeftBorder
= aBorderSize
.Width();
3202 long nLowerBorder
= aBorderSize
.Height();
3205 // Set control at the beginning of a new line.
3206 long nSmallBorderHeight
= nLowerBorder
/ 2;
3207 aNewControlPos
= Point( nLeftBorder
, 0 );
3208 aNewControlPos
+= Point( 0, aDlgSize
.Height() );
3209 aNewControlPos
.Y() -= nSmallBorderHeight
;
3211 pNewDlgSize
= new Size( aDlgSize
);
3212 pNewDlgSize
->Height() -= nSmallBorderHeight
;
3213 pNewDlgSize
->Height() += aNewControlSize
.Height();
3214 pNewDlgSize
->Height() += nLowerBorder
;
3218 // Check if the window has to be resized.
3219 Size
aNewControlRange( 0, aNewControlPos
.Y() );
3220 aNewControlRange
.Height() += aNewControlSize
.Height();
3221 aNewControlRange
.Height() += nLowerBorder
;
3222 if ( aNewControlRange
.Height() > aDlgSize
.Height() )
3223 pNewDlgSize
= new Size( aDlgSize
.Width(), aNewControlRange
.Height() );
3229 SetOutputSizePixel( *pNewDlgSize
);
3232 pControl
->SetPosPixel( aNewControlPos
);
3234 _pUserControls
= new ControlChain_Impl( pControl
, _pUserControls
);
3239 sal_Bool
SvtFileDialog::ContentHasParentFolder( const OUString
& rURL
)
3241 m_aContent
.bindTo( rURL
);
3243 if ( m_aContent
.isInvalid() )
3246 return m_aContent
.hasParentFolder( ) && m_aContent
.isValid();
3249 sal_Bool
SvtFileDialog::ContentCanMakeFolder( const OUString
& rURL
)
3251 m_aContent
.bindTo( rURL
);
3253 if ( m_aContent
.isInvalid() )
3256 return m_aContent
.canCreateFolder( ) && m_aContent
.isValid();
3259 sal_Bool
SvtFileDialog::ContentGetTitle( const OUString
& rURL
, String
& rTitle
)
3261 m_aContent
.bindTo( rURL
);
3263 if ( m_aContent
.isInvalid() )
3267 m_aContent
.getTitle( sTitle
);
3270 return m_aContent
.isValid();
3273 void SvtFileDialog::appendDefaultExtension(String
& _rFileName
,
3274 const String
& _rFilterDefaultExtension
,
3275 const String
& _rFilterExtensions
)
3277 String
aTemp(_rFileName
);
3278 aTemp
.ToLowerAscii();
3279 String
aType(_rFilterExtensions
);
3280 aType
.ToLowerAscii();
3282 if ( ! aType
.EqualsAscii(FILEDIALOG_FILTER_ALL
) )
3284 sal_uInt16 nWildCard
= comphelper::string::getTokenCount(aType
, FILEDIALOG_DEF_EXTSEP
);
3288 for ( nIndex
= 0; nIndex
< nWildCard
; nIndex
++ )
3290 String
aExt(aType
.GetToken( 0, FILEDIALOG_DEF_EXTSEP
, nPos
));
3291 // take care of a leading *
3292 sal_uInt16 nExtOffset
= (aExt
.GetBuffer()[0] == '*' ? 1 : 0);
3293 sal_Unicode
* pExt
= aExt
.GetBufferAccess() + nExtOffset
;
3294 xub_StrLen nExtLen
= aExt
.Len() - nExtOffset
;
3295 xub_StrLen nOffset
= aTemp
.Len() - nExtLen
;
3296 // minimize search by starting at last possible index
3297 if ( aTemp
.Search(pExt
, nOffset
) == nOffset
)
3301 if ( nIndex
>= nWildCard
)
3304 _rFileName
+= _rFilterDefaultExtension
;
3309 void SvtFileDialog::initDefaultPlaces( )
3311 PlacePtr
pRootPlace( new Place( SVT_RESSTR(STR_DEFAULT_DIRECTORY
), GetStandardDir() ) );
3312 _pImp
->_pPlaces
->AppendPlace( pRootPlace
);
3314 // Load from user settings
3315 Sequence
< OUString
> placesUrlsList(officecfg::Office::Common::Misc::FilePickerPlacesUrls::get(m_context
));
3316 Sequence
< OUString
> placesNamesList(officecfg::Office::Common::Misc::FilePickerPlacesNames::get(m_context
));
3318 for(sal_Int32 nPlace
= 0; nPlace
< placesUrlsList
.getLength() && nPlace
< placesNamesList
.getLength(); ++nPlace
)
3320 PlacePtr
pPlace(new Place(placesNamesList
[nPlace
], placesUrlsList
[nPlace
], true));
3321 _pImp
->_pPlaces
->AppendPlace(pPlace
);
3324 // Reset the placesList "updated" state
3325 _pImp
->_pPlaces
->IsUpdated();
3328 IMPL_LINK_NOARG( SvtFileDialog
, Split_Hdl
)
3330 sal_Int32 nSplitPos
= _pSplitter
->GetSplitPosPixel();
3332 // Resize the places list
3333 sal_Int32 nPlaceX
= _pImp
->_pPlaces
->GetPosPixel( ).X();
3334 Size placeSize
= _pImp
->_pPlaces
->GetSizePixel( );
3335 placeSize
.Width() = nSplitPos
- nPlaceX
;
3336 _pImp
->_pPlaces
->SetSizePixel( placeSize
);
3338 // Change Pos and size of the fileview
3339 Point fileViewPos
= _pFileView
->GetPosPixel();
3340 sal_Int32 nOldX
= fileViewPos
.X();
3341 sal_Int32 nNewX
= nSplitPos
+ _pSplitter
->GetSizePixel().Width();
3342 fileViewPos
.X() = nNewX
;
3343 Size fileViewSize
= _pFileView
->GetSizePixel();
3344 fileViewSize
.Width() -= ( nNewX
- nOldX
);
3345 _pFileView
->SetPosSizePixel( fileViewPos
, fileViewSize
);
3347 _pSplitter
->SetPosPixel( Point( nSplitPos
, _pSplitter
->GetPosPixel().Y() ) );
3351 // QueryFolderNameDialog -------------------------------------------------------
3355 QueryFolderNameDialog::QueryFolderNameDialog
3358 const String
& rTitle
,
3359 const String
& rDefaultText
,
3362 ModalDialog( _pParent
, SvtResId( DLG_FPICKER_QUERYFOLDERNAME
) ),
3364 aNameText ( this, SvtResId( FT_SVT_QUERYFOLDERNAME_DLG_NAME
) ),
3365 aNameEdit ( this, SvtResId( ED_SVT_QUERYFOLDERNAME_DLG_NAME
) ),
3366 aNameLine ( this, SvtResId( FL_SVT_QUERYFOLDERNAME_DLG_NAME
) ),
3367 aOKBtn ( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_OK
) ),
3368 aCancelBtn ( this, SvtResId( BT_SVT_QUERYFOLDERNAME_DLG_CANCEL
) )
3372 aNameEdit
.SetText( rDefaultText
);
3373 aNameEdit
.SetSelection( Selection( 0, rDefaultText
.Len() ) );
3374 aOKBtn
.SetClickHdl( LINK( this, QueryFolderNameDialog
, OKHdl
) );
3375 aNameEdit
.SetModifyHdl( LINK( this, QueryFolderNameDialog
, NameHdl
) );
3378 aNameLine
.SetText( *pGroupName
);
3381 // -----------------------------------------------------------------------
3382 IMPL_LINK_NOARG(QueryFolderNameDialog
, OKHdl
)
3385 aNameEdit
.SetText(comphelper::string::strip(aNameEdit
.GetText(), ' '));
3386 EndDialog( RET_OK
);
3390 // -----------------------------------------------------------------------
3391 IMPL_LINK_NOARG(QueryFolderNameDialog
, NameHdl
)
3394 String aName
= comphelper::string::strip(aNameEdit
.GetText(), ' ');
3397 if ( !aOKBtn
.IsEnabled() )
3398 aOKBtn
.Enable( sal_True
);
3402 if ( aOKBtn
.IsEnabled() )
3403 aOKBtn
.Enable( sal_False
);
3411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */