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