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