xref: /AOO41X/main/fpicker/source/office/iodlg.hxx (revision 10ce801889b00990ebdbcb412f4f91e2a9e6f21d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _IODLGIMPL_HXX
24 #define _IODLGIMPL_HXX
25 
26 #ifndef _VCL_DIALOG_HXX
27 #include <vcl/dialog.hxx>
28 #endif
29 #ifndef _SV_BUTTON_HXX
30 #include <vcl/button.hxx>
31 #endif
32 #include <vcl/fixed.hxx>
33 #include <vcl/edit.hxx>
34 #include <vcl/combobox.hxx>
35 #include <vcl/lstbox.hxx>
36 #include <com/sun/star/beans/StringPair.hpp>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <com/sun/star/ucb/IOErrorCode.hpp>
40 #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
41 #include <unotools/confignode.hxx>
42 #include "svl/inettype.hxx"
43 #include "svl/urlfilter.hxx"
44 #include <svl/restrictedpaths.hxx>
45 #include "asyncfilepicker.hxx"
46 #include "OfficeControlAccess.hxx"
47 #include "fpsmartcontent.hxx"
48 
49 #include <set>
50 
51 // @@@ using namespace com::sun::star::ucb;
52 
53 //*****************************************************************************
54 
55 class SvTabListBox;
56 class SvStringsDtor;
57 class SvtFileView;
58 struct ControlChain_Impl;
59 class SvtFileDialogFilter_Impl;
60 
61 //*****************************************************************************
62 
63 #define SFXWB_INSERT            ( 0x04000000L | WB_OPEN )
64 #define SFXWB_PASSWORD          WB_PASSWORD
65 #define SFXWB_READONLY          WB_READONLY
66 #define SFXWB_PATHDIALOG        WB_PATH
67 #define SFXWB_CLASSPATH         ( 0x08000000L | SFXWB_PATHDIALOG )
68 #define SFXWB_SHOWALLFOLDER     0x10000000L     // alle Ordner auch Mail/News/...
69 #define SFXWB_MULTISELECTION    0x20000000L     // Multiselection an
70 #define SFXWB_NOREMOTE          0x40000000L
71 #define SFXWB_SHOWVERSIONS      0x80000000L     // Versionsauswahl anzeigen
72 
73 #define SFX_EXTRA_AUTOEXTENSION     0x00000001L
74 #define SFX_EXTRA_FILTEROPTIONS     0x00000002L
75 #define SFX_EXTRA_SHOWVERSIONS      0x00000004L
76 #define SFX_EXTRA_INSERTASLINK      0x00000008L
77 #define SFX_EXTRA_SHOWPREVIEW       0x00000010L
78 #define SFX_EXTRA_TEMPLATES         0x00000020L
79 #define SFX_EXTRA_PLAYBUTTON        0x00000040L
80 #define SFX_EXTRA_SELECTION         0x00000080L
81 #define SFX_EXTRA_IMAGE_TEMPLATE    0x00000100L
82 
83 #define RET_MANAGER             100
84 
85 #define FILEDIALOG_FILTER_ALL   "*.*"
86 
87 //*****************************************************************************
88 // SvtFileDialog
89 //*****************************************************************************
90 
91 class SvtExpFileDlg_Impl;
92 class SvtFileDialog : public ModalDialog, public ::svt::IFilePickerController
93 {
94 private:
95     // originally from VclFileDialog
96     ControlChain_Impl*          _pUserControls;
97 
98     CheckBox*                   _pCbReadOnly;
99     CheckBox*                   _pCbLinkBox;
100     CheckBox*                   _pCbPreviewBox;
101     CheckBox*                   _pCbSelection;
102     PushButton*                 _pPbPlay;
103     Window*                     _pPrevWin;
104     FixedBitmap*                _pPrevBmp;
105     SvtFileView*                _pFileView;
106     ::svt::IFilePickerListener* _pFileNotifier;
107     SvtExpFileDlg_Impl*         _pImp;
108     WinBits                     _nExtraBits;
109     sal_Bool                        _bIsInExecute   :   1;
110 
111     ImageList                   m_aImages;
112     ::svt::SmartContent         m_aContent;
113 
114     ::svt::RestrictedPaths      m_aURLFilter;
115     ::std::set< Control* >      m_aDisabledControls;
116 
117     ::utl::OConfigurationNode   m_aConfiguration;
118     ::rtl::Reference< ::svt::AsyncPickerAction >
119                                 m_pCurrentAsyncAction;
120     ::com::sun::star::uno::Reference<
121         ::com::sun::star::ui::dialogs::XDialogClosedListener >
122                                 m_xListener;
123     bool                        m_bInExecuteAsync;
124     bool                        m_bHasFilename;
125 
126     DECL_STATIC_LINK( SvtFileDialog, FilterSelectHdl_Impl, ListBox* );
127     DECL_STATIC_LINK( SvtFileDialog, NewFolderHdl_Impl, PushButton* );
128     DECL_STATIC_LINK( SvtFileDialog, ViewHdl_Impl, ImageButton* );
129     DECL_STATIC_LINK( SvtFileDialog, OpenHdl_Impl, void* );
130     DECL_LINK       (                CancelHdl_Impl, void* );
131     DECL_STATIC_LINK( SvtFileDialog, FileNameGetFocusHdl_Impl, void* );
132     DECL_STATIC_LINK( SvtFileDialog, FileNameModifiedHdl_Impl, void* );
133 
134     void                        Init_Impl( WinBits nBits );
135     /** find a filter with the given wildcard
136     @param _rFilter
137         the wildcard pattern to look for in the filter list
138     @param _bMultiExt
139         allow for filters with more than one extension pattern
140     @param _rFilterChanged
141         set to <TRUE/> if the filter changed
142     @return
143         the filter which has been found
144     */
145     SvtFileDialogFilter_Impl*   FindFilter_Impl( const String& _rFilter,
146                                                  sal_Bool _bMultiExt,
147                                                  sal_Bool& _rFilterChanged
148                                                  );
149     void                        ExecuteFilter();
150     void                        OpenMultiSelection_Impl();
151     void                        AddControls_Impl( );
152 
153     DECL_LINK( SelectHdl_Impl, SvTabListBox* );
154     DECL_LINK( DblClickHdl_Impl, SvTabListBox* );
155     DECL_LINK( EntrySelectHdl_Impl, ComboBox* );
156     DECL_LINK( OpenDoneHdl_Impl, SvtFileView* );
157     DECL_LINK( AutoExtensionHdl_Impl, CheckBox* );
158     DECL_LINK( ClickHdl_Impl, CheckBox* );
159     DECL_LINK( PlayButtonHdl_Impl, PushButton* );
160 
161     // entfernt einen Filter mit Wildcards aus dem Path und gibt in zurueck
162     sal_Bool IsolateFilterFromPath_Impl( String& rPath, String& rFilter );
163 
164     void    implArrangeControls();
165     void    implUpdateImages( );
166 
167 protected:
168     virtual long                Notify( NotifyEvent& rNEvt );
169     void                        EnableInternet( sal_Bool bInternet );
170 
171     // originally from VclFileDialog
172     Link                        _aOKHdl;
173     Link                        _aFileSelectHdl;
174     Link                        _aFilterSelectHdl;
175 
176     String                      _aPath;
177     String                      _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                                 ~SvtFileDialog();
204 
205     virtual long                OK();
206     virtual short               Execute();
207     virtual void                StartExecuteModal( const Link& rEndDialogHdl );
208 
209             void                FileSelect();
210             void                FilterSelect();
211 
212     void                        SetBlackList( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList );
213     const ::com::sun::star::uno::Sequence< ::rtl::OUString >& GetBlackList() const;
214     void                        SetStandardDir( const String& rStdDir );
215     const String&               GetStandardDir() const;
216     SvStringsDtor*              GetPathList() const;        // bei MultiSelektion
217 
218             void                AddFilter( const String& rFilter,
219                                            const String& rType );
220 
221             void                AddFilterGroup(
222                 const String& _rFilter,
223                 const com::sun::star::uno::Sequence< com::sun::star::beans::StringPair >& rFilters );
224 
225             void                SetCurFilter( const String& rFilter );
226             String              GetCurFilter() const;
227             sal_uInt16              GetFilterCount() const;
228             const String&       GetFilterName( sal_uInt16 nPos ) const;
229 
230     virtual void                Resize();
231     virtual void                DataChanged( const DataChangedEvent& _rDCEvt );
232 
233     void                        PrevLevel_Impl();
234     void                        OpenURL_Impl( const String& rURL );
235 
236     inline SvtFileView*         GetView() const;
237 
238     void                        DisableSaveLastDirectory();
239     void                        InitSize();
240     void                        UpdateControls( const String& rURL );
241     void                        EnableAutocompletion( sal_Bool _bEnable = sal_True );
242 
SetFileCallback(::svt::IFilePickerListener * pNotifier)243     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     String                      getCurrentFileText( ) const;
254     void                        setCurrentFileText( const String& _rText, bool _bSelectAll = false );
255 
256     void                        onAsyncOperationStarted();
257     void                        onAsyncOperationFinished();
258 
259     void                        displayIOException( const String& _rURL, ::com::sun::star::ucb::IOErrorCode _eCode );
simulateAccessDenied(const String & _rURL)260     void                        simulateAccessDenied( const String& _rURL )
261     {
262         displayIOException( _rURL, ::com::sun::star::ucb::IOErrorCode_ACCESS_DENIED );
263     }
264 
265     // originally from VclFileDialog
266     virtual sal_Bool                AddControl( Window* pControl, sal_Bool bNewLine = sal_False );
267 
268     // inline
269     inline void                 SetPath( const String& rNewURL );
270     inline void                 SetHasFilename( bool bHasFilename );
271     inline const String&        GetPath() const;
272     inline void                 SetDefaultExt( const String& rExt );
273     inline void                 EraseDefaultExt( xub_StrLen _nIndex = 0 );
274     inline const String&        GetDefaultExt() const;
275     inline void                 SetOKHdl( const Link& rLink );
276     inline const Link&          GetOKHdl() const;
277     inline void                 SetFileSelectHdl( const Link& rLink );
278     inline const Link&          GetFileSelectHdl() const;
279     inline void                 SetFilterSelectHdl( const Link& rLink );
280     inline const Link&          GetFilterSelectHdl() const;
281 
GetButtonImage(sal_uInt16 _nButtonId) const282     inline Image                GetButtonImage( sal_uInt16 _nButtonId ) const { return m_aImages.GetImage( _nButtonId ); }
283 
ContentIsFolder(const rtl::OUString & rURL)284     sal_Bool                    ContentIsFolder( const rtl::OUString& rURL ) { return m_aContent.isFolder( rURL ) && m_aContent.isValid(); }
285     sal_Bool                    ContentHasParentFolder( const rtl::OUString& rURL );
286     sal_Bool                    ContentCanMakeFolder( const rtl::OUString& rURL );
287     sal_Bool                    ContentGetTitle( const rtl::OUString& rURL, String& rTitle );
288 
289     /** updates the sizes of the listboxes in the bottom area of the dialog, and of their labels,
290         according to the space occupied by the current label texts
291 
292         @since #i42824#
293     */
294     void                        updateListboxLabelSizes();
295 
296     /** checks URL access permissions
297 
298         <p>with the "restriction" feature we have in the file dialog, it's possible that
299         only certain URLs can be browsed. This method checks whether a given URL belongs
300         to this set of permitted URLs.</p>
301 
302         <p>If no "access restriction" is effective, this method always returns <TRUE/>.</p>
303     */
isUrlAllowed(const String & _rURL) const304     inline bool isUrlAllowed( const String& _rURL ) const { return m_aURLFilter.isUrlAllowed( _rURL ); }
305 
306 private:
307     SvtFileDialogFilter_Impl*   implAddFilter( const String& _rFilter, const String& _rType );
308 
309     /** updates _pUserFilter with a new filter
310         <p>No checks for necessity are made.</p>
311         @param _bAllowUserDefExt
312             set to <TRUE/> if a filter like "*.txt" should reset the DefaultExtension to doc.
313             <p>
314             In a file-save-dialog this would have the following effect:<br/>
315             Say that auto-extension is checked, and the user enters *.txt, while a non-txt filter is selected.<br/>
316             If _bAllowUserDefExt is set to <TRUE/>, then a user input of "foo" would save a foo.txt, but in a format
317             which is determined by the filter selected (which is no txt file as said above).<br/>
318             If _bAllowUserDefExt is set to <FALSE/>, the default extension will be the one of the selected filter, means
319             in the above scenario a file "foo.<ext>" will be saved where ext is the extension of the selected filter.
320             </p>
321         @return <TRUE/> if the new filter is "*.*"
322     */
323     sal_Bool                    createNewUserFilter( const String& _rNewFilter, sal_Bool _bAllowUserDefExt );
324 
325     sal_uInt16                  adjustFilter( const String& _rFilter );
326 
327     // IFilePickerController, needed by OControlAccess
328     virtual Control*            getControl( sal_Int16 _nControlId, sal_Bool _bLabelControl = sal_False ) const;
329     virtual void                enableControl( sal_Int16 _nControlId, sal_Bool _bEnable );
330     virtual String              getCurFilter( ) const;
331 
332     String                      implGetInitialURL( const String& _rPath, const String& _rFallback );
333 
334     /// initializes the special URL lists, such as our favourites and our restricted paths
335     void                        implInitializeSpecialURLLists( );
336 
337     /// executes a certain FileView action asynchronously
338     void                        executeAsync(
339                                     ::svt::AsyncPickerAction::Action _eAction,
340                                     const String& _rURL,
341                                     const String& _rFilter
342                                 );
343 
344     /** helper function to check and append the default filter extension if
345         necessary.
346         The function checks if the specified filename already contains one of
347         the valid extensions of the specified filter. If not the filter default
348         extension is appended to the filename.
349 
350         @param _rFileName the filename which is checked and extended if necessary.
351         @param _rFilterDefaultExtension the default extension of the used filter.
352         @param _rFilterExtensions a list of one or more valid filter extensions
353                of the used filter.
354 
355      */
356     static void                 appendDefaultExtension(
357                                         String& _rFileName,
358                                         const String& _rFilterDefaultExtension,
359                                         const String& _rFilterExtensions);
360 };
361 
362 //***************************************************************************
363 
SetPath(const String & rNewURL)364 inline void SvtFileDialog::SetPath( const String& rNewURL )
365 {
366     _aPath = rNewURL;
367 }
368 
369 //***************************************************************************
370 
SetHasFilename(bool bHasFilename)371 inline void SvtFileDialog::SetHasFilename( bool bHasFilename )
372 {
373     m_bHasFilename = bHasFilename;
374 }
375 
376 //***************************************************************************
377 
GetPath() const378 inline const String& SvtFileDialog::GetPath() const
379 {
380     return _aPath;
381 }
382 
383 //***************************************************************************
384 
SetDefaultExt(const String & rExt)385 inline void SvtFileDialog::SetDefaultExt( const String& rExt )
386 {
387     _aDefExt = rExt;
388 }
389 
EraseDefaultExt(xub_StrLen _nIndex)390 inline void SvtFileDialog::EraseDefaultExt( xub_StrLen _nIndex )
391 {
392     _aDefExt.Erase( _nIndex );
393 }
394 
GetDefaultExt() const395 inline const String& SvtFileDialog::GetDefaultExt() const
396 {
397     return _aDefExt;
398 }
399 
400 //*****************************************************************************
401 
SetOKHdl(const Link & rLink)402 inline void SvtFileDialog::SetOKHdl
403 (
404     const Link& rLink
405 )
406 {
407     _aOKHdl = rLink;
408 }
409 
410 //*****************************************************************************
411 
GetOKHdl() const412 inline const Link& SvtFileDialog::GetOKHdl() const
413 {
414     return _aOKHdl;
415 }
416 
417 //*****************************************************************************
418 
SetFileSelectHdl(const Link & rLink)419 inline void SvtFileDialog::SetFileSelectHdl
420 (
421     const Link& rLink
422 )
423 {
424     _aFileSelectHdl = rLink;
425 }
426 
427 //*****************************************************************************
428 
GetFileSelectHdl() const429 inline const Link& SvtFileDialog::GetFileSelectHdl() const
430 {
431     return _aFileSelectHdl;
432 }
433 
434 //*****************************************************************************
435 
SetFilterSelectHdl(const Link & rLink)436 inline void SvtFileDialog::SetFilterSelectHdl
437 (
438     const Link& rLink
439 )
440 {
441     _aFilterSelectHdl = rLink;
442 }
443 
444 //*****************************************************************************
445 
GetFilterSelectHdl() const446 inline const Link& SvtFileDialog::GetFilterSelectHdl() const
447 {
448     return _aFilterSelectHdl;
449 }
450 
451 //*****************************************************************************
452 
GetView() const453 inline SvtFileView* SvtFileDialog::GetView() const
454 {
455     return _pFileView;
456 }
457 
458 //*****************************************************************************
459 //*****************************************************************************
460 //*****************************************************************************
461 
462 class SvtFilePicker;
463 
464 #define FILE_SELECTION_CHANGED  1
465 #define DIRECTORY_CHANGED       2
466 #define HELP_REQUESTED          3
467 #define CTRL_STATE_CHANGED      4
468 #define DIALOG_SIZE_CHANGED     5
469 
470 
471 #endif // #ifndef _IODLG_HXX
472