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