1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _IODLGIMPL_HXX
20 #define _IODLGIMPL_HXX
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 "asyncfilepicker.hxx"
38 #include "OfficeControlAccess.hxx"
39 #include "fpsmartcontent.hxx"
40 #include <comphelper/configuration.hxx>
41 #include <comphelper/processfactory.hxx>
45 // @@@ using namespace com::sun::star::ucb;
47 //*****************************************************************************
51 struct ControlChain_Impl
;
52 class SvtFileDialogFilter_Impl
;
54 //*****************************************************************************
56 #define SFXWB_INSERT ( 0x04000000L | WB_OPEN )
57 #define SFXWB_PASSWORD WB_PASSWORD
58 #define SFXWB_READONLY WB_READONLY
59 #define SFXWB_PATHDIALOG WB_PATH
60 #define SFXWB_CLASSPATH ( 0x08000000L | SFXWB_PATHDIALOG )
61 #define SFXWB_SHOWALLFOLDER 0x10000000L // all directories including Mail/News/...
62 #define SFXWB_MULTISELECTION 0x20000000L // activate Multiselection
63 #define SFXWB_NOREMOTE 0x40000000L
64 #define SFXWB_SHOWVERSIONS 0x80000000L // show version selection
66 #define SFX_EXTRA_AUTOEXTENSION 0x00000001L
67 #define SFX_EXTRA_FILTEROPTIONS 0x00000002L
68 #define SFX_EXTRA_SHOWVERSIONS 0x00000004L
69 #define SFX_EXTRA_INSERTASLINK 0x00000008L
70 #define SFX_EXTRA_SHOWPREVIEW 0x00000010L
71 #define SFX_EXTRA_TEMPLATES 0x00000020L
72 #define SFX_EXTRA_PLAYBUTTON 0x00000040L
73 #define SFX_EXTRA_SELECTION 0x00000080L
74 #define SFX_EXTRA_IMAGE_TEMPLATE 0x00000100L
76 #define FILEDIALOG_FILTER_ALL "*.*"
78 //*****************************************************************************
80 //*****************************************************************************
82 class SvtExpFileDlg_Impl
;
83 class SvtFileDialog
: public ModalDialog
, public ::svt::IFilePickerController
86 // originally from VclFileDialog
87 ControlChain_Impl
* _pUserControls
;
89 CheckBox
* _pCbReadOnly
;
90 CheckBox
* _pCbLinkBox
;
91 CheckBox
* _pCbPreviewBox
;
92 CheckBox
* _pCbSelection
;
95 FixedBitmap
* _pPrevBmp
;
96 SvtFileView
* _pFileView
;
98 ::svt::IFilePickerListener
* _pFileNotifier
;
99 SvtExpFileDlg_Impl
* _pImp
;
101 sal_Bool _bIsInExecute
: 1;
104 ::svt::SmartContent m_aContent
;
106 ::std::set
< Control
* > m_aDisabledControls
;
108 ::utl::OConfigurationNode m_aConfiguration
;
109 ::rtl::Reference
< ::svt::AsyncPickerAction
>
110 m_pCurrentAsyncAction
;
111 ::com::sun::star::uno::Reference
<
112 ::com::sun::star::ui::dialogs::XDialogClosedListener
>
114 bool m_bInExecuteAsync
;
116 ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_context
;
118 DECL_STATIC_LINK( SvtFileDialog
, FilterSelectHdl_Impl
, ListBox
* );
119 DECL_STATIC_LINK( SvtFileDialog
, NewFolderHdl_Impl
, PushButton
* );
120 DECL_STATIC_LINK( SvtFileDialog
, ViewHdl_Impl
, ImageButton
* );
121 DECL_STATIC_LINK( SvtFileDialog
, OpenHdl_Impl
, void* );
122 DECL_LINK ( CancelHdl_Impl
, void* );
123 DECL_STATIC_LINK( SvtFileDialog
, FileNameGetFocusHdl_Impl
, void* );
124 DECL_STATIC_LINK( SvtFileDialog
, FileNameModifiedHdl_Impl
, void* );
126 DECL_STATIC_LINK( SvtFileDialog
, URLBoxModifiedHdl_Impl
, void* );
127 DECL_STATIC_LINK( SvtFileDialog
, ConnectToServerPressed_Hdl
, void* );
129 DECL_LINK ( AddPlacePressed_Hdl
, void* );
130 DECL_LINK ( RemovePlacePressed_Hdl
, void* );
131 DECL_LINK ( Split_Hdl
, void* );
133 void Init_Impl( WinBits nBits
);
134 /** find a filter with the given wildcard
136 the wildcard pattern to look for in the filter list
138 allow for filters with more than one extension pattern
139 @param _rFilterChanged
140 set to <TRUE/> if the filter changed
142 the filter which has been found
144 SvtFileDialogFilter_Impl
* FindFilter_Impl( const String
& _rFilter
,
146 sal_Bool
& _rFilterChanged
148 void ExecuteFilter();
149 void OpenMultiSelection_Impl();
150 void AddControls_Impl( );
152 DECL_LINK( SelectHdl_Impl
, SvTabListBox
* );
153 DECL_LINK(DblClickHdl_Impl
, void *);
154 DECL_LINK(EntrySelectHdl_Impl
, void *);
155 DECL_LINK( OpenDoneHdl_Impl
, SvtFileView
* );
156 DECL_LINK(AutoExtensionHdl_Impl
, void *);
157 DECL_LINK( ClickHdl_Impl
, CheckBox
* );
158 DECL_LINK(PlayButtonHdl_Impl
, void *);
161 // removes a filter with wildcards from the path and returns it
162 sal_Bool
IsolateFilterFromPath_Impl( String
& rPath
, String
& rFilter
);
164 void implArrangeControls();
165 void implUpdateImages( );
168 virtual long Notify( NotifyEvent
& rNEvt
);
169 void EnableInternet( sal_Bool bInternet
);
171 // originally from VclFileDialog
173 Link _aFileSelectHdl
;
174 Link _aFilterSelectHdl
;
179 void ReleaseOwnership( Window
* pUserControl
);
181 /** enables or disables the complete UI of the file picker, with only offering a
184 This method preserves the "enabled" state of its controls in the following sense:
185 If you disable a certain control, then disable the dialog UI, then enable the dialog
186 UI, the control will still be disabled.
187 This is under the assumption that you'll use EnableControl. Direct access to the control
188 (such as pControl->Enable()) will break this.
190 void EnableUI( sal_Bool _bEnable
);
192 /** enables or disables a control
194 You are strongly encouraged to prefer this method over pControl->Enable( _bEnable ). See
195 <member>EnableUI</member> for details.
197 void EnableControl( Control
* _pControl
, sal_Bool _bEnable
);
198 short PrepareExecute();
201 SvtFileDialog( Window
* _pParent
, WinBits nBits
, WinBits nExtraBits
);
202 SvtFileDialog( Window
* _pParent
, WinBits nBits
);
206 virtual short Execute();
207 virtual void StartExecuteModal( const Link
& rEndDialogHdl
);
212 void SetBlackList( const ::com::sun::star::uno::Sequence
< OUString
>& rBlackList
);
213 const ::com::sun::star::uno::Sequence
< OUString
>& GetBlackList() const;
214 void SetStandardDir( const String
& rStdDir
);
215 const String
& GetStandardDir() const;
216 std::vector
<OUString
> GetPathList() const; // for MultiSelection
218 void AddFilter( const String
& rFilter
,
219 const String
& rType
);
222 const String
& _rFilter
,
223 const com::sun::star::uno::Sequence
< com::sun::star::beans::StringPair
>& rFilters
);
225 void SetCurFilter( const String
& rFilter
);
226 String
GetCurFilter() const;
227 sal_uInt16
GetFilterCount() const;
228 const String
& GetFilterName( sal_uInt16 nPos
) const;
230 virtual void Resize();
231 virtual void DataChanged( const DataChangedEvent
& _rDCEvt
);
233 void PrevLevel_Impl();
234 void OpenURL_Impl( const String
& rURL
);
236 inline SvtFileView
* GetView() const;
238 void DisableSaveLastDirectory();
240 void UpdateControls( const String
& rURL
);
241 void EnableAutocompletion( sal_Bool _bEnable
= sal_True
);
243 void SetFileCallback( ::svt::IFilePickerListener
*pNotifier
) { _pFileNotifier
= pNotifier
; }
245 sal_Int32
getTargetColorDepth();
246 sal_Int32
getAvailableWidth();
247 sal_Int32
getAvailableHeight();
248 void setImage( sal_Int16 aImageFormat
, const ::com::sun::star::uno::Any
& rImage
);
249 sal_Bool
setShowState( sal_Bool bShowState
);
250 sal_Bool
getShowState();
251 sal_Bool
isAutoExtensionEnabled();
253 String
getCurrentFileText( ) const;
254 void setCurrentFileText( const String
& _rText
, bool _bSelectAll
= false );
256 void onAsyncOperationStarted();
257 void onAsyncOperationFinished();
259 void RemovablePlaceSelected(bool enable
= true);
261 void displayIOException( const String
& _rURL
, ::com::sun::star::ucb::IOErrorCode _eCode
);
263 // originally from VclFileDialog
264 virtual sal_Bool
AddControl( Window
* pControl
, sal_Bool bNewLine
= sal_False
);
267 inline void SetPath( const String
& rNewURL
);
268 inline void SetHasFilename( bool bHasFilename
);
269 inline const String
& GetPath() const;
270 inline void SetDefaultExt( const String
& rExt
);
271 inline void EraseDefaultExt( xub_StrLen _nIndex
= 0 );
272 inline const String
& GetDefaultExt() const;
273 inline void SetOKHdl( const Link
& rLink
);
274 inline const Link
& GetOKHdl() const;
275 inline void SetFileSelectHdl( const Link
& rLink
);
276 inline const Link
& GetFileSelectHdl() const;
277 inline void SetFilterSelectHdl( const Link
& rLink
);
278 inline const Link
& GetFilterSelectHdl() const;
280 inline Image
GetButtonImage( sal_uInt16 _nButtonId
) const { return m_aImages
.GetImage( _nButtonId
); }
282 sal_Bool
ContentIsFolder( const OUString
& rURL
) { return m_aContent
.isFolder( rURL
) && m_aContent
.isValid(); }
283 sal_Bool
ContentHasParentFolder( const OUString
& rURL
);
284 sal_Bool
ContentCanMakeFolder( const OUString
& rURL
);
285 sal_Bool
ContentGetTitle( const OUString
& rURL
, String
& rTitle
);
287 /** updates the sizes of the listboxes in the bottom area of the dialog, and of their labels,
288 according to the space occupied by the current label texts
292 void updateListboxLabelSizes();
295 SvtFileDialogFilter_Impl
* implAddFilter( const String
& _rFilter
, const String
& _rType
);
297 /** updates _pUserFilter with a new filter
298 <p>No checks for necessity are made.</p>
299 @param _bAllowUserDefExt
300 set to <TRUE/> if a filter like "*.txt" should reset the DefaultExtension to doc.
302 In a file-save-dialog this would have the following effect:<br/>
303 Say that auto-extension is checked, and the user enters *.txt, while a non-txt filter is selected.<br/>
304 If _bAllowUserDefExt is set to <TRUE/>, then a user input of "foo" would save a foo.txt, but in a format
305 which is determined by the filter selected (which is no txt file as said above).<br/>
306 If _bAllowUserDefExt is set to <FALSE/>, the default extension will be the one of the selected filter, means
307 in the above scenario a file "foo.<ext>" will be saved where ext is the extension of the selected filter.
309 @return <TRUE/> if the new filter is "*.*"
311 sal_Bool
createNewUserFilter( const String
& _rNewFilter
, sal_Bool _bAllowUserDefExt
);
313 sal_uInt16
adjustFilter( const String
& _rFilter
);
315 // IFilePickerController, needed by OControlAccess
316 virtual Control
* getControl( sal_Int16 _nControlId
, sal_Bool _bLabelControl
= sal_False
) const;
317 virtual void enableControl( sal_Int16 _nControlId
, sal_Bool _bEnable
);
318 virtual String
getCurFilter( ) const;
320 String
implGetInitialURL( const String
& _rPath
, const String
& _rFallback
);
322 /// executes a certain FileView action asynchronously
324 ::svt::AsyncPickerAction::Action _eAction
,
326 const String
& _rFilter
329 /** helper function to check and append the default filter extension if
331 The function checks if the specified filename already contains one of
332 the valid extensions of the specified filter. If not the filter default
333 extension is appended to the filename.
335 @param _rFileName the filename which is checked and extended if necessary.
336 @param _rFilterDefaultExtension the default extension of the used filter.
337 @param _rFilterExtensions a list of one or more valid filter extensions
341 static void appendDefaultExtension(
343 const String
& _rFilterDefaultExtension
,
344 const String
& _rFilterExtensions
);
346 void initDefaultPlaces( );
349 //***************************************************************************
351 inline void SvtFileDialog::SetPath( const String
& rNewURL
)
356 //***************************************************************************
358 inline void SvtFileDialog::SetHasFilename( bool bHasFilename
)
360 m_bHasFilename
= bHasFilename
;
363 //***************************************************************************
365 inline const String
& SvtFileDialog::GetPath() const
370 //***************************************************************************
372 inline void SvtFileDialog::SetDefaultExt( const String
& rExt
)
377 inline void SvtFileDialog::EraseDefaultExt( xub_StrLen _nIndex
)
379 _aDefExt
.Erase( _nIndex
);
382 inline const String
& SvtFileDialog::GetDefaultExt() const
387 //*****************************************************************************
389 inline void SvtFileDialog::SetOKHdl
397 //*****************************************************************************
399 inline const Link
& SvtFileDialog::GetOKHdl() const
404 //*****************************************************************************
406 inline void SvtFileDialog::SetFileSelectHdl
411 _aFileSelectHdl
= rLink
;
414 //*****************************************************************************
416 inline const Link
& SvtFileDialog::GetFileSelectHdl() const
418 return _aFileSelectHdl
;
421 //*****************************************************************************
423 inline void SvtFileDialog::SetFilterSelectHdl
428 _aFilterSelectHdl
= rLink
;
431 //*****************************************************************************
433 inline const Link
& SvtFileDialog::GetFilterSelectHdl() const
435 return _aFilterSelectHdl
;
438 //*****************************************************************************
440 inline SvtFileView
* SvtFileDialog::GetView() const
445 //*****************************************************************************
446 //*****************************************************************************
447 //*****************************************************************************
449 #define FILE_SELECTION_CHANGED 1
450 #define DIRECTORY_CHANGED 2
451 #define HELP_REQUESTED 3
452 #define CTRL_STATE_CHANGED 4
453 #define DIALOG_SIZE_CHANGED 5
456 #endif // #ifndef _IODLG_HXX
458 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */