1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iodlg.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _IODLGIMPL_HXX
31 #define _IODLGIMPL_HXX
33 #ifndef _VCL_DIALOG_HXX
34 #include <vcl/dialog.hxx>
36 #ifndef _SV_BUTTON_HXX
37 #include <vcl/button.hxx>
39 #include <vcl/fixed.hxx>
40 #include <vcl/edit.hxx>
41 #include <vcl/combobox.hxx>
42 #include <vcl/lstbox.hxx>
43 #include <com/sun/star/beans/StringPair.hpp>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
46 #include <com/sun/star/ucb/IOErrorCode.hpp>
47 #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
48 #include <unotools/confignode.hxx>
49 #include "svtools/inettype.hxx"
50 #include "svtools/urlfilter.hxx"
51 #include <svtools/restrictedpaths.hxx>
52 #include "asyncfilepicker.hxx"
53 #include "OfficeControlAccess.hxx"
54 #include "fpsmartcontent.hxx"
58 // @@@ using namespace com::sun::star::ucb;
60 //*****************************************************************************
65 struct ControlChain_Impl
;
66 class SvtFileDialogFilter_Impl
;
68 //*****************************************************************************
70 #define SFXWB_INSERT ( 0x04000000L | WB_OPEN )
71 #define SFXWB_PASSWORD WB_PASSWORD
72 #define SFXWB_READONLY WB_READONLY
73 #define SFXWB_PATHDIALOG WB_PATH
74 #define SFXWB_CLASSPATH ( 0x08000000L | SFXWB_PATHDIALOG )
75 #define SFXWB_SHOWALLFOLDER 0x10000000L // alle Ordner auch Mail/News/...
76 #define SFXWB_MULTISELECTION 0x20000000L // Multiselection an
77 #define SFXWB_NOREMOTE 0x40000000L
78 #define SFXWB_SHOWVERSIONS 0x80000000L // Versionsauswahl anzeigen
80 #define SFX_EXTRA_AUTOEXTENSION 0x00000001L
81 #define SFX_EXTRA_FILTEROPTIONS 0x00000002L
82 #define SFX_EXTRA_SHOWVERSIONS 0x00000004L
83 #define SFX_EXTRA_INSERTASLINK 0x00000008L
84 #define SFX_EXTRA_SHOWPREVIEW 0x00000010L
85 #define SFX_EXTRA_TEMPLATES 0x00000020L
86 #define SFX_EXTRA_PLAYBUTTON 0x00000040L
87 #define SFX_EXTRA_SELECTION 0x00000080L
88 #define SFX_EXTRA_IMAGE_TEMPLATE 0x00000100L
90 #define RET_MANAGER 100
92 #define FILEDIALOG_FILTER_ALL "*.*"
94 //*****************************************************************************
96 //*****************************************************************************
98 class SvtExpFileDlg_Impl
;
99 class SvtFileDialog
: public ModalDialog
, public ::svt::IFilePickerController
102 // originally from VclFileDialog
103 ControlChain_Impl
* _pUserControls
;
105 CheckBox
* _pCbReadOnly
;
106 CheckBox
* _pCbLinkBox
;
107 CheckBox
* _pCbPreviewBox
;
108 CheckBox
* _pCbSelection
;
109 PushButton
* _pPbPlay
;
111 FixedBitmap
* _pPrevBmp
;
112 SvtFileView
* _pFileView
;
113 ::svt::IFilePickerListener
* _pFileNotifier
;
114 SvtExpFileDlg_Impl
* _pImp
;
116 BOOL _bIsInExecute
: 1;
119 ::svt::SmartContent m_aContent
;
121 ::svt::RestrictedPaths m_aURLFilter
;
122 ::std::set
< Control
* > m_aDisabledControls
;
124 ::utl::OConfigurationNode m_aConfiguration
;
125 ::rtl::Reference
< ::svt::AsyncPickerAction
>
126 m_pCurrentAsyncAction
;
127 ::com::sun::star::uno::Reference
<
128 ::com::sun::star::ui::dialogs::XDialogClosedListener
>
130 bool m_bInExecuteAsync
;
133 DECL_STATIC_LINK( SvtFileDialog
, FilterSelectHdl_Impl
, ListBox
* );
134 DECL_STATIC_LINK( SvtFileDialog
, NewFolderHdl_Impl
, PushButton
* );
135 DECL_STATIC_LINK( SvtFileDialog
, ViewHdl_Impl
, ImageButton
* );
136 DECL_STATIC_LINK( SvtFileDialog
, OpenHdl_Impl
, void* );
137 DECL_LINK ( CancelHdl_Impl
, void* );
138 DECL_STATIC_LINK( SvtFileDialog
, FileNameGetFocusHdl_Impl
, void* );
139 DECL_STATIC_LINK( SvtFileDialog
, FileNameModifiedHdl_Impl
, void* );
141 void Init_Impl( WinBits nBits
);
142 /** find a filter with the given wildcard
144 the wildcard pattern to look for in the filter list
146 allow for filters with more than one extension pattern
147 @param _rFilterChanged
148 set to <TRUE/> if the filter changed
150 the filter which has been found
152 SvtFileDialogFilter_Impl
* FindFilter_Impl( const String
& _rFilter
,
154 sal_Bool
& _rFilterChanged
156 void ExecuteFilter();
157 void OpenMultiSelection_Impl();
158 void AddControls_Impl( );
160 DECL_LINK( SelectHdl_Impl
, SvTabListBox
* );
161 DECL_LINK( DblClickHdl_Impl
, SvTabListBox
* );
162 DECL_LINK( EntrySelectHdl_Impl
, ComboBox
* );
163 DECL_LINK( OpenDoneHdl_Impl
, SvtFileView
* );
164 DECL_LINK( AutoExtensionHdl_Impl
, CheckBox
* );
165 DECL_LINK( ClickHdl_Impl
, CheckBox
* );
166 DECL_LINK( PlayButtonHdl_Impl
, PushButton
* );
168 // entfernt einen Filter mit Wildcards aus dem Path und gibt in zurueck
169 BOOL
IsolateFilterFromPath_Impl( String
& rPath
, String
& rFilter
);
171 void implArrangeControls();
172 void implUpdateImages( );
175 virtual long Notify( NotifyEvent
& rNEvt
);
176 void EnableInternet( BOOL bInternet
);
178 // originally from VclFileDialog
180 Link _aFileSelectHdl
;
181 Link _aFilterSelectHdl
;
186 void ReleaseOwnerShip( Window
* pUserControl
);
188 /** enables or disables the complete UI of the file picker, with only offering a
191 This method preserves the "enabled" state of its controls in the following sense:
192 If you disable a certain control, then disable the dialog UI, then enable the dialog
193 UI, the control will still be disabled.
194 This is under the assumption that you'll use EnableControl. Direct access to the control
195 (such as pControl->Enable()) will break this.
197 void EnableUI( BOOL _bEnable
);
199 /** enables or disables a control
201 You are strongly encouraged to prefer this method over pControl->Enable( _bEnable ). See
202 <member>EnableUI</member> for details.
204 void EnableControl( Control
* _pControl
, BOOL _bEnable
);
205 short PrepareExecute();
208 SvtFileDialog( Window
* _pParent
, WinBits nBits
, WinBits nExtraBits
);
209 SvtFileDialog( Window
* _pParent
, WinBits nBits
);
213 virtual short Execute();
214 virtual void StartExecuteModal( const Link
& rEndDialogHdl
);
219 void SetBlackList( const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& rBlackList
);
220 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& GetBlackList() const;
221 void SetStandardDir( const String
& rStdDir
);
222 const String
& GetStandardDir() const;
223 SvStringsDtor
* GetPathList() const; // bei MultiSelektion
225 void AddFilter( const String
& rFilter
,
226 const String
& rType
);
229 const String
& _rFilter
,
230 const com::sun::star::uno::Sequence
< com::sun::star::beans::StringPair
>& rFilters
);
232 void SetCurFilter( const String
& rFilter
);
233 String
GetCurFilter() const;
234 USHORT
GetFilterCount() const;
235 const String
& GetFilterName( USHORT nPos
) const;
237 virtual void Resize();
238 virtual void DataChanged( const DataChangedEvent
& _rDCEvt
);
240 void PrevLevel_Impl();
241 void OpenURL_Impl( const String
& rURL
);
243 inline SvtFileView
* GetView() const;
245 void DisableSaveLastDirectory();
247 void UpdateControls( const String
& rURL
);
248 void EnableAutocompletion( BOOL _bEnable
= TRUE
);
250 void SetFileCallback( ::svt::IFilePickerListener
*pNotifier
) { _pFileNotifier
= pNotifier
; }
252 sal_Int32
getTargetColorDepth();
253 sal_Int32
getAvailableWidth();
254 sal_Int32
getAvailableHeight();
255 void setImage( sal_Int16 aImageFormat
, const ::com::sun::star::uno::Any
& rImage
);
256 sal_Bool
setShowState( sal_Bool bShowState
);
257 sal_Bool
getShowState();
258 sal_Bool
isAutoExtensionEnabled();
260 String
getCurrentFileText( ) const;
261 void setCurrentFileText( const String
& _rText
, bool _bSelectAll
= false );
263 void onAsyncOperationStarted();
264 void onAsyncOperationFinished();
266 void displayIOException( const String
& _rURL
, ::com::sun::star::ucb::IOErrorCode _eCode
);
267 void simulateAccessDenied( const String
& _rURL
)
269 displayIOException( _rURL
, ::com::sun::star::ucb::IOErrorCode_ACCESS_DENIED
);
272 // originally from VclFileDialog
273 virtual BOOL
AddControl( Window
* pControl
, BOOL bNewLine
= FALSE
);
276 inline void SetPath( const String
& rNewURL
);
277 inline void SetHasFilename( bool bHasFilename
);
278 inline const String
& GetPath() const;
279 inline void SetDefaultExt( const String
& rExt
);
280 inline void EraseDefaultExt( xub_StrLen _nIndex
= 0 );
281 inline const String
& GetDefaultExt() const;
282 inline void SetOKHdl( const Link
& rLink
);
283 inline const Link
& GetOKHdl() const;
284 inline void SetFileSelectHdl( const Link
& rLink
);
285 inline const Link
& GetFileSelectHdl() const;
286 inline void SetFilterSelectHdl( const Link
& rLink
);
287 inline const Link
& GetFilterSelectHdl() const;
289 inline Image
GetButtonImage( sal_uInt16 _nButtonId
) const { return m_aImages
.GetImage( _nButtonId
); }
291 sal_Bool
ContentIsFolder( const rtl::OUString
& rURL
) { return m_aContent
.isFolder( rURL
) && m_aContent
.isValid(); }
292 sal_Bool
ContentHasParentFolder( const rtl::OUString
& rURL
);
293 sal_Bool
ContentCanMakeFolder( const rtl::OUString
& rURL
);
294 sal_Bool
ContentGetTitle( const rtl::OUString
& rURL
, String
& rTitle
);
296 /** updates the sizes of the listboxes in the bottom area of the dialog, and of their labels,
297 according to the space occupied by the current label texts
301 void updateListboxLabelSizes();
303 /** checks URL access permissions
305 <p>with the "restriction" feature we have in the file dialog, it's possible that
306 only certain URLs can be browsed. This method checks whether a given URL belongs
307 to this set of permitted URLs.</p>
309 <p>If no "access restriction" is effective, this method always returns <TRUE/>.</p>
311 inline bool isUrlAllowed( const String
& _rURL
) const { return m_aURLFilter
.isUrlAllowed( _rURL
); }
314 SvtFileDialogFilter_Impl
* implAddFilter( const String
& _rFilter
, const String
& _rType
);
316 /** updates _pUserFilter with a new filter
317 <p>No checks for necessity are made.</p>
318 @param _bAllowUserDefExt
319 set to <TRUE/> if a filter like "*.txt" should reset the DefaultExtension to doc.
321 In a file-save-dialog this would have the following effect:<br/>
322 Say that auto-extension is checked, and the user enters *.txt, while a non-txt filter is selected.<br/>
323 If _bAllowUserDefExt is set to <TRUE/>, then a user input of "foo" would save a foo.txt, but in a format
324 which is determined by the filter selected (which is no txt file as said above).<br/>
325 If _bAllowUserDefExt is set to <FALSE/>, the default extension will be the one of the selected filter, means
326 in the above scenario a file "foo.<ext>" will be saved where ext is the extension of the selected filter.
328 @return <TRUE/> if the new filter is "*.*"
330 sal_Bool
createNewUserFilter( const String
& _rNewFilter
, sal_Bool _bAllowUserDefExt
);
332 sal_uInt16
adjustFilter( const String
& _rFilter
);
334 // IFilePickerController, needed by OControlAccess
335 virtual Control
* getControl( sal_Int16 _nControlId
, sal_Bool _bLabelControl
= sal_False
) const;
336 virtual void enableControl( sal_Int16 _nControlId
, sal_Bool _bEnable
);
337 virtual String
getCurFilter( ) const;
339 String
implGetInitialURL( const String
& _rPath
, const String
& _rFallback
);
341 /// initializes the special URL lists, such as our favourites and our restricted paths
342 void implInitializeSpecialURLLists( );
344 /// executes a certain FileView action asynchronously
346 ::svt::AsyncPickerAction::Action _eAction
,
348 const String
& _rFilter
351 /** helper function to check and append the default filter extension if
353 The function checks if the specified filename already contains one of
354 the valid extensions of the specified filter. If not the filter default
355 extension is appended to the filename.
357 @param _rFileName the filename which is checked and extended if necessary.
358 @param _rFilterDefaultExtension the default extension of the used filter.
359 @param _rFilterExtensions a list of one or more valid filter extensions
363 static void appendDefaultExtension(
365 const String
& _rFilterDefaultExtension
,
366 const String
& _rFilterExtensions
);
369 //***************************************************************************
371 inline void SvtFileDialog::SetPath( const String
& rNewURL
)
376 //***************************************************************************
378 inline void SvtFileDialog::SetHasFilename( bool bHasFilename
)
380 m_bHasFilename
= bHasFilename
;
383 //***************************************************************************
385 inline const String
& SvtFileDialog::GetPath() const
390 //***************************************************************************
392 inline void SvtFileDialog::SetDefaultExt( const String
& rExt
)
397 inline void SvtFileDialog::EraseDefaultExt( xub_StrLen _nIndex
)
399 _aDefExt
.Erase( _nIndex
);
402 inline const String
& SvtFileDialog::GetDefaultExt() const
407 //*****************************************************************************
409 inline void SvtFileDialog::SetOKHdl
417 //*****************************************************************************
419 inline const Link
& SvtFileDialog::GetOKHdl() const
424 //*****************************************************************************
426 inline void SvtFileDialog::SetFileSelectHdl
431 _aFileSelectHdl
= rLink
;
434 //*****************************************************************************
436 inline const Link
& SvtFileDialog::GetFileSelectHdl() const
438 return _aFileSelectHdl
;
441 //*****************************************************************************
443 inline void SvtFileDialog::SetFilterSelectHdl
448 _aFilterSelectHdl
= rLink
;
451 //*****************************************************************************
453 inline const Link
& SvtFileDialog::GetFilterSelectHdl() const
455 return _aFilterSelectHdl
;
458 //*****************************************************************************
460 inline SvtFileView
* SvtFileDialog::GetView() const
465 //*****************************************************************************
466 //*****************************************************************************
467 //*****************************************************************************
471 #define FILE_SELECTION_CHANGED 1
472 #define DIRECTORY_CHANGED 2
473 #define HELP_REQUESTED 3
474 #define CTRL_STATE_CHANGED 4
475 #define DIALOG_SIZE_CHANGED 5
478 #endif // #ifndef _IODLG_HXX