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