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 "asyncfilepicker.hxx"
38 : #include "OfficeControlAccess.hxx"
39 : #include "fpsmartcontent.hxx"
40 : #include <comphelper/configuration.hxx>
41 : #include <comphelper/processfactory.hxx>
42 :
43 : #include <set>
44 :
45 : // @@@ using namespace com::sun::star::ucb;
46 :
47 :
48 :
49 : class SvTabListBox;
50 : class SvtFileView;
51 : struct ControlChain_Impl;
52 : class SvtFileDialogFilter_Impl;
53 :
54 :
55 :
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
65 :
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
75 :
76 : #define FILEDIALOG_FILTER_ALL "*.*"
77 :
78 :
79 : // SvtFileDialog
80 :
81 :
82 : class SvtExpFileDlg_Impl;
83 : class SvtFileDialog : public ModalDialog, public ::svt::IFilePickerController
84 : {
85 : private:
86 : // originally from VclFileDialog
87 : ControlChain_Impl* _pUserControls;
88 :
89 : CheckBox* _pCbReadOnly;
90 : CheckBox* _pCbLinkBox;
91 : CheckBox* _pCbPreviewBox;
92 : CheckBox* _pCbSelection;
93 : PushButton* _pPbPlay;
94 : Window* _pPrevWin;
95 : FixedBitmap* _pPrevBmp;
96 : SvtFileView* _pFileView;
97 : Splitter* _pSplitter;
98 : ::svt::IFilePickerListener* _pFileNotifier;
99 : SvtExpFileDlg_Impl* _pImp;
100 : WinBits _nExtraBits;
101 : sal_Bool _bIsInExecute : 1;
102 :
103 : ImageList m_aImages;
104 : ::svt::SmartContent m_aContent;
105 :
106 : ::std::set< Control* > m_aDisabledControls;
107 :
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 >
113 : m_xListener;
114 : bool m_bInExecuteAsync;
115 : bool m_bHasFilename;
116 : ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_context;
117 :
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* );
125 :
126 : DECL_STATIC_LINK( SvtFileDialog, URLBoxModifiedHdl_Impl, void* );
127 : DECL_STATIC_LINK( SvtFileDialog, ConnectToServerPressed_Hdl, void* );
128 :
129 : DECL_LINK ( AddPlacePressed_Hdl, void* );
130 : DECL_LINK ( RemovePlacePressed_Hdl, void* );
131 : DECL_LINK ( Split_Hdl, void* );
132 :
133 : void Init_Impl( WinBits nBits );
134 : /** find a filter with the given wildcard
135 : @param _rFilter
136 : the wildcard pattern to look for in the filter list
137 : @param _bMultiExt
138 : allow for filters with more than one extension pattern
139 : @param _rFilterChanged
140 : set to <TRUE/> if the filter changed
141 : @return
142 : the filter which has been found
143 : */
144 : SvtFileDialogFilter_Impl* FindFilter_Impl( const OUString& _rFilter,
145 : sal_Bool _bMultiExt,
146 : sal_Bool& _rFilterChanged
147 : );
148 : void ExecuteFilter();
149 : void OpenMultiSelection_Impl();
150 : void AddControls_Impl( );
151 :
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 *);
159 :
160 :
161 : // removes a filter with wildcards from the path and returns it
162 : sal_Bool IsolateFilterFromPath_Impl( OUString& rPath, OUString& rFilter );
163 :
164 : void implArrangeControls();
165 : void implUpdateImages( );
166 :
167 : protected:
168 : virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
169 : void EnableInternet( sal_Bool bInternet );
170 :
171 : // originally from VclFileDialog
172 : Link _aOKHdl;
173 : Link _aFileSelectHdl;
174 : Link _aFilterSelectHdl;
175 :
176 : OUString _aPath;
177 : OUString _aDefExt;
178 :
179 : void ReleaseOwnership( Window* pUserControl );
180 :
181 : /** enables or disables the complete UI of the file picker, with only offering a
182 : cancel button
183 :
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.
189 : */
190 : void EnableUI( sal_Bool _bEnable );
191 :
192 : /** enables or disables a control
193 :
194 : You are strongly encouraged to prefer this method over pControl->Enable( _bEnable ). See
195 : <member>EnableUI</member> for details.
196 : */
197 : void EnableControl( Control* _pControl, sal_Bool _bEnable );
198 : short PrepareExecute();
199 :
200 : public:
201 : SvtFileDialog( Window* _pParent, WinBits nBits, WinBits nExtraBits );
202 : SvtFileDialog( Window* _pParent, WinBits nBits );
203 : virtual ~SvtFileDialog();
204 :
205 : virtual long OK();
206 : virtual short Execute() SAL_OVERRIDE;
207 : virtual void StartExecuteModal( const Link& rEndDialogHdl ) SAL_OVERRIDE;
208 :
209 : void FileSelect();
210 : void FilterSelect();
211 :
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 OUString& rStdDir );
215 : const OUString& GetStandardDir() const;
216 : std::vector<OUString> GetPathList() const; // for MultiSelection
217 :
218 : void AddFilter( const OUString& rFilter,
219 : const OUString& rType );
220 :
221 : void AddFilterGroup(
222 : const OUString& _rFilter,
223 : const com::sun::star::uno::Sequence< com::sun::star::beans::StringPair >& rFilters );
224 :
225 : void SetCurFilter( const OUString& rFilter );
226 : OUString GetCurFilter() const;
227 : sal_uInt16 GetFilterCount() const;
228 : const OUString& GetFilterName( sal_uInt16 nPos ) const;
229 :
230 : virtual void Resize() SAL_OVERRIDE;
231 : virtual void DataChanged( const DataChangedEvent& _rDCEvt ) SAL_OVERRIDE;
232 :
233 : void PrevLevel_Impl();
234 : void OpenURL_Impl( const OUString& rURL );
235 :
236 : inline SvtFileView* GetView() const;
237 :
238 : void DisableSaveLastDirectory();
239 : void InitSize();
240 : void UpdateControls( const OUString& rURL );
241 : void EnableAutocompletion( sal_Bool _bEnable = sal_True );
242 :
243 0 : void SetFileCallback( ::svt::IFilePickerListener *pNotifier ) { _pFileNotifier = pNotifier; }
244 :
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();
252 :
253 : OUString getCurrentFileText( ) const;
254 : void setCurrentFileText( const OUString& _rText, bool _bSelectAll = false );
255 :
256 : void onAsyncOperationStarted();
257 : void onAsyncOperationFinished();
258 :
259 : void RemovablePlaceSelected(bool enable = true);
260 :
261 : void displayIOException( const OUString& _rURL, ::com::sun::star::ucb::IOErrorCode _eCode );
262 :
263 : // originally from VclFileDialog
264 : virtual sal_Bool AddControl( Window* pControl, sal_Bool bNewLine = sal_False );
265 :
266 : // inline
267 : inline void SetPath( const OUString& rNewURL );
268 : inline void SetHasFilename( bool bHasFilename );
269 : inline const OUString& GetPath() const;
270 : inline void SetDefaultExt( const OUString& rExt );
271 : inline void EraseDefaultExt( sal_Int32 _nIndex = 0 );
272 : inline const OUString& 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;
279 :
280 0 : inline Image GetButtonImage( sal_uInt16 _nButtonId ) const { return m_aImages.GetImage( _nButtonId ); }
281 :
282 0 : 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, OUString& rTitle );
286 :
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
289 :
290 : @since #i42824#
291 : */
292 : void updateListboxLabelSizes();
293 :
294 : private:
295 : SvtFileDialogFilter_Impl* implAddFilter( const OUString& _rFilter, const OUString& _rType );
296 :
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.
301 : <p>
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.
308 : </p>
309 : @return <TRUE/> if the new filter is "*.*"
310 : */
311 : sal_Bool createNewUserFilter( const OUString& _rNewFilter, sal_Bool _bAllowUserDefExt );
312 :
313 : sal_uInt16 adjustFilter( const OUString& _rFilter );
314 :
315 : // IFilePickerController, needed by OControlAccess
316 : virtual Control* getControl( sal_Int16 _nControlId, sal_Bool _bLabelControl = sal_False ) const SAL_OVERRIDE;
317 : virtual void enableControl( sal_Int16 _nControlId, sal_Bool _bEnable ) SAL_OVERRIDE;
318 : virtual OUString getCurFilter( ) const SAL_OVERRIDE;
319 :
320 : OUString implGetInitialURL( const OUString& _rPath, const OUString& _rFallback );
321 :
322 : /// executes a certain FileView action asynchronously
323 : void executeAsync(
324 : ::svt::AsyncPickerAction::Action _eAction,
325 : const OUString& _rURL,
326 : const OUString& _rFilter
327 : );
328 :
329 : /** helper function to check and append the default filter extension if
330 : necessary.
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.
334 :
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
338 : of the used filter.
339 :
340 : */
341 : static void appendDefaultExtension(
342 : OUString& _rFileName,
343 : const OUString& _rFilterDefaultExtension,
344 : const OUString& _rFilterExtensions);
345 :
346 : void initDefaultPlaces( );
347 : };
348 :
349 :
350 :
351 0 : inline void SvtFileDialog::SetPath( const OUString& rNewURL )
352 : {
353 0 : _aPath = rNewURL;
354 0 : }
355 :
356 :
357 :
358 0 : inline void SvtFileDialog::SetHasFilename( bool bHasFilename )
359 : {
360 0 : m_bHasFilename = bHasFilename;
361 0 : }
362 :
363 :
364 :
365 0 : inline const OUString& SvtFileDialog::GetPath() const
366 : {
367 0 : return _aPath;
368 : }
369 :
370 :
371 :
372 0 : inline void SvtFileDialog::SetDefaultExt( const OUString& rExt )
373 : {
374 0 : _aDefExt = rExt;
375 0 : }
376 :
377 0 : inline void SvtFileDialog::EraseDefaultExt( sal_Int32 _nIndex )
378 : {
379 0 : _aDefExt = _aDefExt.copy( 0, _nIndex );
380 0 : }
381 :
382 0 : inline const OUString& SvtFileDialog::GetDefaultExt() const
383 : {
384 0 : return _aDefExt;
385 : }
386 :
387 :
388 :
389 : inline void SvtFileDialog::SetOKHdl
390 : (
391 : const Link& rLink
392 : )
393 : {
394 : _aOKHdl = rLink;
395 : }
396 :
397 :
398 :
399 : inline const Link& SvtFileDialog::GetOKHdl() const
400 : {
401 : return _aOKHdl;
402 : }
403 :
404 :
405 :
406 : inline void SvtFileDialog::SetFileSelectHdl
407 : (
408 : const Link& rLink
409 : )
410 : {
411 : _aFileSelectHdl = rLink;
412 : }
413 :
414 :
415 :
416 : inline const Link& SvtFileDialog::GetFileSelectHdl() const
417 : {
418 : return _aFileSelectHdl;
419 : }
420 :
421 :
422 :
423 : inline void SvtFileDialog::SetFilterSelectHdl
424 : (
425 : const Link& rLink
426 : )
427 : {
428 : _aFilterSelectHdl = rLink;
429 : }
430 :
431 :
432 :
433 : inline const Link& SvtFileDialog::GetFilterSelectHdl() const
434 : {
435 : return _aFilterSelectHdl;
436 : }
437 :
438 :
439 :
440 0 : inline SvtFileView* SvtFileDialog::GetView() const
441 : {
442 0 : return _pFileView;
443 : }
444 :
445 :
446 :
447 :
448 :
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
454 :
455 :
456 : #endif // #ifndef _IODLG_HXX
457 :
458 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|