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