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 : #ifndef _IODLGIMPL_HXX
20 : #define _IODLGIMPL_HXX
21 :
22 : #include <vcl/dialog.hxx>
23 : #include <vcl/button.hxx>
24 : #include <vcl/fixed.hxx>
25 : #include <vcl/edit.hxx>
26 : #include <vcl/combobox.hxx>
27 : #include <vcl/lstbox.hxx>
28 : #include <vcl/split.hxx>
29 : #include <com/sun/star/beans/StringPair.hpp>
30 : #include <com/sun/star/uno/Any.hxx>
31 : #include <com/sun/star/uno/Sequence.hxx>
32 : #include <com/sun/star/uno/Reference.hxx>
33 : #include <com/sun/star/ucb/IOErrorCode.hpp>
34 : #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
35 : #include <unotools/confignode.hxx>
36 : #include "svl/inettype.hxx"
37 : #include "svl/urlfilter.hxx"
38 : #include <svl/restrictedpaths.hxx>
39 : #include "asyncfilepicker.hxx"
40 : #include "OfficeControlAccess.hxx"
41 : #include "fpsmartcontent.hxx"
42 : #include <comphelper/configuration.hxx>
43 : #include <comphelper/processfactory.hxx>
44 :
45 : #include <set>
46 :
47 : // @@@ using namespace com::sun::star::ucb;
48 :
49 : //*****************************************************************************
50 :
51 : class SvTabListBox;
52 : class SvtFileView;
53 : struct ControlChain_Impl;
54 : class SvtFileDialogFilter_Impl;
55 :
56 : //*****************************************************************************
57 :
58 : #define SFXWB_INSERT ( 0x04000000L | WB_OPEN )
59 : #define SFXWB_PASSWORD WB_PASSWORD
60 : #define SFXWB_READONLY WB_READONLY
61 : #define SFXWB_PATHDIALOG WB_PATH
62 : #define SFXWB_CLASSPATH ( 0x08000000L | SFXWB_PATHDIALOG )
63 : #define SFXWB_SHOWALLFOLDER 0x10000000L // all directories including Mail/News/...
64 : #define SFXWB_MULTISELECTION 0x20000000L // activate Multiselection
65 : #define SFXWB_NOREMOTE 0x40000000L
66 : #define SFXWB_SHOWVERSIONS 0x80000000L // show version selection
67 :
68 : #define SFX_EXTRA_AUTOEXTENSION 0x00000001L
69 : #define SFX_EXTRA_FILTEROPTIONS 0x00000002L
70 : #define SFX_EXTRA_SHOWVERSIONS 0x00000004L
71 : #define SFX_EXTRA_INSERTASLINK 0x00000008L
72 : #define SFX_EXTRA_SHOWPREVIEW 0x00000010L
73 : #define SFX_EXTRA_TEMPLATES 0x00000020L
74 : #define SFX_EXTRA_PLAYBUTTON 0x00000040L
75 : #define SFX_EXTRA_SELECTION 0x00000080L
76 : #define SFX_EXTRA_IMAGE_TEMPLATE 0x00000100L
77 :
78 : #define FILEDIALOG_FILTER_ALL "*.*"
79 :
80 : //*****************************************************************************
81 : // SvtFileDialog
82 : //*****************************************************************************
83 :
84 : class SvtExpFileDlg_Impl;
85 : class SvtFileDialog : public ModalDialog, public ::svt::IFilePickerController
86 : {
87 : private:
88 : // originally from VclFileDialog
89 : ControlChain_Impl* _pUserControls;
90 :
91 : CheckBox* _pCbReadOnly;
92 : CheckBox* _pCbLinkBox;
93 : CheckBox* _pCbPreviewBox;
94 : CheckBox* _pCbSelection;
95 : PushButton* _pPbPlay;
96 : Window* _pPrevWin;
97 : FixedBitmap* _pPrevBmp;
98 : SvtFileView* _pFileView;
99 : Splitter* _pSplitter;
100 : ::svt::IFilePickerListener* _pFileNotifier;
101 : SvtExpFileDlg_Impl* _pImp;
102 : WinBits _nExtraBits;
103 : sal_Bool _bIsInExecute : 1;
104 :
105 : ImageList m_aImages;
106 : ::svt::SmartContent m_aContent;
107 :
108 : ::svt::RestrictedPaths m_aURLFilter;
109 : ::std::set< Control* > m_aDisabledControls;
110 :
111 : ::utl::OConfigurationNode m_aConfiguration;
112 : ::rtl::Reference< ::svt::AsyncPickerAction >
113 : m_pCurrentAsyncAction;
114 : ::com::sun::star::uno::Reference<
115 : ::com::sun::star::ui::dialogs::XDialogClosedListener >
116 : m_xListener;
117 : bool m_bInExecuteAsync;
118 : bool m_bHasFilename;
119 : ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_context;
120 :
121 : DECL_STATIC_LINK( SvtFileDialog, FilterSelectHdl_Impl, ListBox* );
122 : DECL_STATIC_LINK( SvtFileDialog, NewFolderHdl_Impl, PushButton* );
123 : DECL_STATIC_LINK( SvtFileDialog, ViewHdl_Impl, ImageButton* );
124 : DECL_STATIC_LINK( SvtFileDialog, OpenHdl_Impl, void* );
125 : DECL_LINK ( CancelHdl_Impl, void* );
126 : DECL_STATIC_LINK( SvtFileDialog, FileNameGetFocusHdl_Impl, void* );
127 : DECL_STATIC_LINK( SvtFileDialog, FileNameModifiedHdl_Impl, void* );
128 :
129 : DECL_STATIC_LINK( SvtFileDialog, URLBoxModifiedHdl_Impl, void* );
130 : DECL_STATIC_LINK( SvtFileDialog, ConnectToServerPressed_Hdl, void* );
131 :
132 : DECL_LINK ( AddPlacePressed_Hdl, void* );
133 : DECL_LINK ( RemovePlacePressed_Hdl, void* );
134 : DECL_LINK ( Split_Hdl, void* );
135 :
136 : void Init_Impl( WinBits nBits );
137 : /** find a filter with the given wildcard
138 : @param _rFilter
139 : the wildcard pattern to look for in the filter list
140 : @param _bMultiExt
141 : allow for filters with more than one extension pattern
142 : @param _rFilterChanged
143 : set to <TRUE/> if the filter changed
144 : @return
145 : the filter which has been found
146 : */
147 : SvtFileDialogFilter_Impl* FindFilter_Impl( const String& _rFilter,
148 : sal_Bool _bMultiExt,
149 : sal_Bool& _rFilterChanged
150 : );
151 : void ExecuteFilter();
152 : void OpenMultiSelection_Impl();
153 : void AddControls_Impl( );
154 :
155 : DECL_LINK( SelectHdl_Impl, SvTabListBox* );
156 : DECL_LINK(DblClickHdl_Impl, void *);
157 : DECL_LINK(EntrySelectHdl_Impl, void *);
158 : DECL_LINK( OpenDoneHdl_Impl, SvtFileView* );
159 : DECL_LINK(AutoExtensionHdl_Impl, void *);
160 : DECL_LINK( ClickHdl_Impl, CheckBox* );
161 : DECL_LINK(PlayButtonHdl_Impl, void *);
162 :
163 :
164 : // removes a filter with wildcards from the path and returns it
165 : sal_Bool IsolateFilterFromPath_Impl( String& rPath, String& rFilter );
166 :
167 : void implArrangeControls();
168 : void implUpdateImages( );
169 :
170 : protected:
171 : virtual long Notify( NotifyEvent& rNEvt );
172 : void EnableInternet( sal_Bool bInternet );
173 :
174 : // originally from VclFileDialog
175 : Link _aOKHdl;
176 : Link _aFileSelectHdl;
177 : Link _aFilterSelectHdl;
178 :
179 : String _aPath;
180 : String _aDefExt;
181 :
182 : void ReleaseOwnerShip( Window* pUserControl );
183 :
184 : /** enables or disables the complete UI of the file picker, with only offering a
185 : cancel button
186 :
187 : This method preserves the "enabled" state of its controls in the following sense:
188 : If you disable a certain control, then disable the dialog UI, then enable the dialog
189 : UI, the control will still be disabled.
190 : This is under the assumption that you'll use EnableControl. Direct access to the control
191 : (such as pControl->Enable()) will break this.
192 : */
193 : void EnableUI( sal_Bool _bEnable );
194 :
195 : /** enables or disables a control
196 :
197 : You are strongly encouraged to prefer this method over pControl->Enable( _bEnable ). See
198 : <member>EnableUI</member> for details.
199 : */
200 : void EnableControl( Control* _pControl, sal_Bool _bEnable );
201 : short PrepareExecute();
202 :
203 : public:
204 : SvtFileDialog( Window* _pParent, WinBits nBits, WinBits nExtraBits );
205 : SvtFileDialog( Window* _pParent, WinBits nBits );
206 : ~SvtFileDialog();
207 :
208 : virtual long OK();
209 : virtual short Execute();
210 : virtual void StartExecuteModal( const Link& rEndDialogHdl );
211 :
212 : void FileSelect();
213 : void FilterSelect();
214 :
215 : void SetBlackList( const ::com::sun::star::uno::Sequence< OUString >& rBlackList );
216 : const ::com::sun::star::uno::Sequence< OUString >& GetBlackList() const;
217 : void SetStandardDir( const String& rStdDir );
218 : const String& GetStandardDir() const;
219 : std::vector<OUString> GetPathList() const; // for MultiSelection
220 :
221 : void AddFilter( const String& rFilter,
222 : const String& rType );
223 :
224 : void AddFilterGroup(
225 : const String& _rFilter,
226 : const com::sun::star::uno::Sequence< com::sun::star::beans::StringPair >& rFilters );
227 :
228 : void SetCurFilter( const String& rFilter );
229 : String GetCurFilter() const;
230 : sal_uInt16 GetFilterCount() const;
231 : const String& GetFilterName( sal_uInt16 nPos ) const;
232 :
233 : virtual void Resize();
234 : virtual void DataChanged( const DataChangedEvent& _rDCEvt );
235 :
236 : void PrevLevel_Impl();
237 : void OpenURL_Impl( const String& rURL );
238 :
239 : inline SvtFileView* GetView() const;
240 :
241 : void DisableSaveLastDirectory();
242 : void InitSize();
243 : void UpdateControls( const String& rURL );
244 : void EnableAutocompletion( sal_Bool _bEnable = sal_True );
245 :
246 0 : void SetFileCallback( ::svt::IFilePickerListener *pNotifier ) { _pFileNotifier = pNotifier; }
247 :
248 : sal_Int32 getTargetColorDepth();
249 : sal_Int32 getAvailableWidth();
250 : sal_Int32 getAvailableHeight();
251 : void setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& rImage );
252 : sal_Bool setShowState( sal_Bool bShowState );
253 : sal_Bool getShowState();
254 : sal_Bool isAutoExtensionEnabled();
255 :
256 : String getCurrentFileText( ) const;
257 : void setCurrentFileText( const String& _rText, bool _bSelectAll = false );
258 :
259 : void onAsyncOperationStarted();
260 : void onAsyncOperationFinished();
261 :
262 : void RemovablePlaceSelected(bool enable = true);
263 :
264 : void displayIOException( const String& _rURL, ::com::sun::star::ucb::IOErrorCode _eCode );
265 0 : void simulateAccessDenied( const String& _rURL )
266 : {
267 0 : displayIOException( _rURL, ::com::sun::star::ucb::IOErrorCode_ACCESS_DENIED );
268 0 : }
269 :
270 : // originally from VclFileDialog
271 : virtual sal_Bool AddControl( Window* pControl, sal_Bool bNewLine = sal_False );
272 :
273 : // inline
274 : inline void SetPath( const String& rNewURL );
275 : inline void SetHasFilename( bool bHasFilename );
276 : inline const String& GetPath() const;
277 : inline void SetDefaultExt( const String& rExt );
278 : inline void EraseDefaultExt( xub_StrLen _nIndex = 0 );
279 : inline const String& GetDefaultExt() const;
280 : inline void SetOKHdl( const Link& rLink );
281 : inline const Link& GetOKHdl() const;
282 : inline void SetFileSelectHdl( const Link& rLink );
283 : inline const Link& GetFileSelectHdl() const;
284 : inline void SetFilterSelectHdl( const Link& rLink );
285 : inline const Link& GetFilterSelectHdl() const;
286 :
287 0 : inline Image GetButtonImage( sal_uInt16 _nButtonId ) const { return m_aImages.GetImage( _nButtonId ); }
288 :
289 0 : sal_Bool ContentIsFolder( const OUString& rURL ) { return m_aContent.isFolder( rURL ) && m_aContent.isValid(); }
290 : sal_Bool ContentHasParentFolder( const OUString& rURL );
291 : sal_Bool ContentCanMakeFolder( const OUString& rURL );
292 : sal_Bool ContentGetTitle( const OUString& rURL, String& rTitle );
293 :
294 : /** updates the sizes of the listboxes in the bottom area of the dialog, and of their labels,
295 : according to the space occupied by the current label texts
296 :
297 : @since #i42824#
298 : */
299 : void updateListboxLabelSizes();
300 :
301 : /** checks URL access permissions
302 :
303 : <p>with the "restriction" feature we have in the file dialog, it's possible that
304 : only certain URLs can be browsed. This method checks whether a given URL belongs
305 : to this set of permitted URLs.</p>
306 :
307 : <p>If no "access restriction" is effective, this method always returns <TRUE/>.</p>
308 : */
309 0 : inline bool isUrlAllowed( const String& _rURL ) const { return m_aURLFilter.isUrlAllowed( _rURL ); }
310 :
311 : private:
312 : SvtFileDialogFilter_Impl* implAddFilter( const String& _rFilter, const String& _rType );
313 :
314 : /** updates _pUserFilter with a new filter
315 : <p>No checks for necessity are made.</p>
316 : @param _bAllowUserDefExt
317 : set to <TRUE/> if a filter like "*.txt" should reset the DefaultExtension to doc.
318 : <p>
319 : In a file-save-dialog this would have the following effect:<br/>
320 : Say that auto-extension is checked, and the user enters *.txt, while a non-txt filter is selected.<br/>
321 : If _bAllowUserDefExt is set to <TRUE/>, then a user input of "foo" would save a foo.txt, but in a format
322 : which is determined by the filter selected (which is no txt file as said above).<br/>
323 : If _bAllowUserDefExt is set to <FALSE/>, the default extension will be the one of the selected filter, means
324 : in the above scenario a file "foo.<ext>" will be saved where ext is the extension of the selected filter.
325 : </p>
326 : @return <TRUE/> if the new filter is "*.*"
327 : */
328 : sal_Bool createNewUserFilter( const String& _rNewFilter, sal_Bool _bAllowUserDefExt );
329 :
330 : sal_uInt16 adjustFilter( const String& _rFilter );
331 :
332 : // IFilePickerController, needed by OControlAccess
333 : virtual Control* getControl( sal_Int16 _nControlId, sal_Bool _bLabelControl = sal_False ) const;
334 : virtual void enableControl( sal_Int16 _nControlId, sal_Bool _bEnable );
335 : virtual String getCurFilter( ) const;
336 :
337 : String implGetInitialURL( const String& _rPath, const String& _rFallback );
338 :
339 : /// executes a certain FileView action asynchronously
340 : void executeAsync(
341 : ::svt::AsyncPickerAction::Action _eAction,
342 : const String& _rURL,
343 : const String& _rFilter
344 : );
345 :
346 : /** helper function to check and append the default filter extension if
347 : necessary.
348 : The function checks if the specified filename already contains one of
349 : the valid extensions of the specified filter. If not the filter default
350 : extension is appended to the filename.
351 :
352 : @param _rFileName the filename which is checked and extended if necessary.
353 : @param _rFilterDefaultExtension the default extension of the used filter.
354 : @param _rFilterExtensions a list of one or more valid filter extensions
355 : of the used filter.
356 :
357 : */
358 : static void appendDefaultExtension(
359 : String& _rFileName,
360 : const String& _rFilterDefaultExtension,
361 : const String& _rFilterExtensions);
362 :
363 : void initDefaultPlaces( );
364 : };
365 :
366 : //***************************************************************************
367 :
368 0 : inline void SvtFileDialog::SetPath( const String& rNewURL )
369 : {
370 0 : _aPath = rNewURL;
371 0 : }
372 :
373 : //***************************************************************************
374 :
375 0 : inline void SvtFileDialog::SetHasFilename( bool bHasFilename )
376 : {
377 0 : m_bHasFilename = bHasFilename;
378 0 : }
379 :
380 : //***************************************************************************
381 :
382 0 : inline const String& SvtFileDialog::GetPath() const
383 : {
384 0 : return _aPath;
385 : }
386 :
387 : //***************************************************************************
388 :
389 0 : inline void SvtFileDialog::SetDefaultExt( const String& rExt )
390 : {
391 0 : _aDefExt = rExt;
392 0 : }
393 :
394 0 : inline void SvtFileDialog::EraseDefaultExt( xub_StrLen _nIndex )
395 : {
396 0 : _aDefExt.Erase( _nIndex );
397 0 : }
398 :
399 0 : inline const String& SvtFileDialog::GetDefaultExt() const
400 : {
401 0 : return _aDefExt;
402 : }
403 :
404 : //*****************************************************************************
405 :
406 : inline void SvtFileDialog::SetOKHdl
407 : (
408 : const Link& rLink
409 : )
410 : {
411 : _aOKHdl = rLink;
412 : }
413 :
414 : //*****************************************************************************
415 :
416 : inline const Link& SvtFileDialog::GetOKHdl() const
417 : {
418 : return _aOKHdl;
419 : }
420 :
421 : //*****************************************************************************
422 :
423 : inline void SvtFileDialog::SetFileSelectHdl
424 : (
425 : const Link& rLink
426 : )
427 : {
428 : _aFileSelectHdl = rLink;
429 : }
430 :
431 : //*****************************************************************************
432 :
433 : inline const Link& SvtFileDialog::GetFileSelectHdl() const
434 : {
435 : return _aFileSelectHdl;
436 : }
437 :
438 : //*****************************************************************************
439 :
440 : inline void SvtFileDialog::SetFilterSelectHdl
441 : (
442 : const Link& rLink
443 : )
444 : {
445 : _aFilterSelectHdl = rLink;
446 : }
447 :
448 : //*****************************************************************************
449 :
450 : inline const Link& SvtFileDialog::GetFilterSelectHdl() const
451 : {
452 : return _aFilterSelectHdl;
453 : }
454 :
455 : //*****************************************************************************
456 :
457 0 : inline SvtFileView* SvtFileDialog::GetView() const
458 : {
459 0 : return _pFileView;
460 : }
461 :
462 : //*****************************************************************************
463 : //*****************************************************************************
464 : //*****************************************************************************
465 :
466 : #define FILE_SELECTION_CHANGED 1
467 : #define DIRECTORY_CHANGED 2
468 : #define HELP_REQUESTED 3
469 : #define CTRL_STATE_CHANGED 4
470 : #define DIALOG_SIZE_CHANGED 5
471 :
472 :
473 : #endif // #ifndef _IODLG_HXX
474 :
475 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|