xref: /AOO41X/main/sfx2/inc/sfx2/filedlghelper.hxx (revision 353d8f4d17010cd2d0ea815067cad67e477f2bee)
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 _FILEDLGHELPER_HXX
24 #define _FILEDLGHELPER_HXX
25 
26 #include "sal/config.h"
27 #include "sfx2/dllapi.h"
28 #include "sal/types.h"
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <rtl/ustring.hxx>
32 #include <tools/solar.h>
33 #include <tools/string.hxx>
34 #include <tools/errcode.hxx>
35 #include <vcl/dialog.hxx>
36 #include <vcl/edit.hxx>
37 #ifndef _SV_BUTTON_HXX
38 #include <vcl/button.hxx>
39 #endif
40 #include <vcl/graph.hxx>
41 #include <sfx2/sfxdefs.hxx>
42 #include <sfx2/sfxuno.hxx>
43 
44 //-----------------------------------------------------------------------------
45 
46 namespace com
47 {
48     namespace sun
49     {
50         namespace star
51         {
52             namespace ui
53             {
54                 namespace dialogs
55                 {
56                     class XFilePicker;
57                     class XFilePickerListener;
58                     struct FilePickerEvent;
59                     struct DialogClosedEvent;
60                 }
61             }
62         }
63     }
64 }
65 
66 class SfxItemSet;
67 class SvStringsDtor;
68 class Window;
69 
70 //-----------------------------------------------------------------------------
71 /*
72 #define WB_PATH                 0x00100000L
73 #define WB_OPEN                 0x00200000L
74 #define WB_SAVEAS               0x00400000L
75 #define WB_PASSWORD             0x01000000L
76 #define WB_READONLY             0x02000000L
77 */
78 
79 #define SFXWB_INSERT            ( 0x04000000L | WB_OPEN )   // ((WinBits)0x00200000)
80 #define SFXWB_PASSWORD          WB_PASSWORD                 // ((WinBits)0x01000000)
81 #define SFXWB_READONLY          WB_READONLY                 // ((WinBits)0x02000000)
82 #define SFXWB_PATHDIALOG        WB_PATH                     // ((WinBits)0x00100000)
83 #define SFXWB_CLASSPATH         ( 0x08000000L | SFXWB_PATHDIALOG )
84 #define SFXWB_SHOWALLFOLDER     0x10000000L     // alle Ordner auch Mail/News/...
85 #define SFXWB_MULTISELECTION    0x20000000L     // Multiselection an
86 #define SFXWB_NOREMOTE          0x40000000L
87 #define SFXWB_SHOWVERSIONS      0x80000000L     // Versionsauswahl anzeigen
88 
89 #define SFXWB_GRAPHIC           0x00800000L     // FileOpen with link and preview box
90 #define SFXWB_SHOWSTYLES        0x01000000L     // FileOpen with link and preview box and styles
91 
92 #define SFXWB_EXPORT            ( 0x040000000L | WB_SAVEAS )    // Export dialog
93 
94 #define FILEDIALOG_FILTER_ALL   "*.*"
95 
96 #define FILE_OPEN_SERVICE_NAME      "com.sun.star.ui.dialogs.FilePicker"
97 #define FOLDER_PICKER_SERVICE_NAME  "com.sun.star.ui.dialogs.FolderPicker"
98 #define FILE_OPEN_SERVICE_NAME_SYSTEM "com.sun.star.ui.dialogs.SystemFilePicker"
99 #define FILE_OPEN_SERVICE_NAME_OOO   "com.sun.star.ui.dialogs.OfficeFilePicker"
100 
101 //-----------------------------------------------------------------------------
102 
103 namespace sfx2 {
104 
105 class FileDialogHelper_Impl;
106 
107 class SFX2_DLLPUBLIC FileDialogHelper
108 {
109 public:
110     enum Context                        // context where the FileDialogHelper is used
111     {
112         UNKNOWN_CONTEXT,                // unknown context
113         SW_INSERT_GRAPHIC,              // insert graphic in writer
114         SW_INSERT_SOUND,                // insert sound in writer
115         SW_INSERT_VIDEO,                // insert video in writer
116         SC_INSERT_GRAPHIC,              // insert graphic in calc
117         SC_INSERT_SOUND,                // insert sound in calc
118         SC_INSERT_VIDEO,                // insert video in calc
119         SD_INSERT_GRAPHIC,              // insert graphic in draw
120         SD_INSERT_SOUND,                // insert sound in draw
121         SD_INSERT_VIDEO,                // insert video in draw
122         SD_EXPORT,                      // export in draw
123         SI_EXPORT,                      // export in impress
124         SW_EXPORT                       // export in writer
125     };
126 
127 private:
128     Link    m_aDialogClosedLink;
129     ErrCode m_nError;
130 
131     ::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePickerListener > mxImp;
132     FileDialogHelper_Impl   *mpImp;
133 
134 //#if 0 // _SOLAR__PRIVATE
135 
136     SAL_DLLPRIVATE sal_Int16 getDialogType( sal_Int64 nFlags ) const;
137 
138 //#endif
139 
140 public:
141                             FileDialogHelper( sal_Int64 nFlags,
142                                               const String& rFactory,
143                                               sal_Int16 nDialog,
144                                               SfxFilterFlags nMust,
145                                               SfxFilterFlags nDont );
146 
147                             FileDialogHelper( sal_Int64 nFlags,
148                                               const String& rFact,
149                                               sal_Int16 nDialog,
150                                               SfxFilterFlags nMust,
151                                               SfxFilterFlags nDont,
152                                               const String& rStandardDir,
153                                               const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList);
154 
155                             FileDialogHelper( sal_Int64 nFlags,
156                                               const String& rFactory,
157                                               SfxFilterFlags nMust = 0,
158                                               SfxFilterFlags nDont = 0 );
159 
160                             FileDialogHelper( sal_Int16 nDialogType,
161                                               sal_Int64 nFlags,
162                                               const String& rFactory,
163                                               SfxFilterFlags nMust = 0,
164                                               SfxFilterFlags nDont = 0 );
165 
166                             FileDialogHelper( sal_Int16 nDialogType,
167                                               sal_Int64 nFlags,
168                                               const String& rFactory,
169                                               sal_Int16 nDialog,
170                                               SfxFilterFlags nMust,
171                                               SfxFilterFlags nDont,
172                                               const String& rStandardDir,
173                                               const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList);
174 
175                             FileDialogHelper( sal_Int64 nFlags );
176 
177                             FileDialogHelper( sal_Int16 nDialogType,
178                                               sal_Int64 nFlags,
179                                               Window* _pPreferredParent = NULL );
180 
181                             FileDialogHelper( sal_Int16 nDialogType,
182                                               sal_Int64 nFlags,
183                                               const ::rtl::OUString& aFilterUIName,
184                                               const ::rtl::OUString& aExtName,
185                                               const ::rtl::OUString& rStandardDir,
186                                               const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList,
187                                               Window* _pPreferredParent = NULL );
188 
189 
190     virtual                 ~FileDialogHelper();
191 
192     ErrCode                 Execute();
193     void                    StartExecuteModal( const Link& rEndDialogHdl );
GetError() const194     inline ErrCode          GetError() const { return m_nError; }
195     sal_Int16               GetDialogType() const;
196     sal_Bool                IsPasswordEnabled() const;
197     String                  GetRealFilter() const;
198 
199     void                    SetTitle( const String&  rNewTitle );
200     String                  GetPath() const;
201 
202     /** @deprected: Don't use this method to retrieve the selected files
203         There are file picker which can provide multiple selected file which belong
204         to different folders. As this method always provides the root folder for all selected
205         files this cannot work.
206     */
207     ::com::sun::star::uno::Sequence< ::rtl::OUString > GetMPath() const;
208 
209     /** Provides the selected files with full path information */
210     ::com::sun::star::uno::Sequence< ::rtl::OUString > GetSelectedFiles() const;
211 
212     void                     AddFilter( const String& rFilterName, const String& rExtension );
213     void                     SetCurrentFilter( const String& rFilter );
214 
215     /** sets an initial display directory/file name
216 
217         @deprecated
218             don't use this method. It contains a lot of magic in determining whether the
219             last segment of the given path/URL denotes a file name or a folder, and by
220             definition, it cannot succeed with this magic *all* the time - there will
221             always be scenarios where it fails.
222 
223             Use SetDisplayFolder and SetFileName.
224     */
225     void                     SetDisplayDirectory( const String& rPath );
226 
227     /** sets a new folder whose content is to be displayed in the file picker
228 
229         @param _rURL
230             specifies the URL of the folder whose content is to be displayed.<br/>
231             If the URL doesn't denote a valid (existent and accessible) folder, the
232             request is silently dropped.
233         @throws ::com::sun::star::uno::RuntimeException
234             if the invocation of any of the file picker or UCB methods throws a RuntimeException.
235     */
236     void                     SetDisplayFolder( const String& _rURL );
237 
238     /** sets an initial file name to display
239 
240         This method is usually used in "save-as" contexts, where the application should
241         suggest an initial name for the file to save.
242 
243         Calling this method is nearly equivalent to calling <code>GetFilePicker().setDefaultName( _rFileName )</code>,
244         with the following differences:
245         <ul><li>The FileDialogHelper remembers the given file name, and upon execution,
246                 strips its extension if the dialog is set up for "automatic file name extension".</li>
247             <li>Exceptions thrown from the <code>XFilePicker</code> are caught and silenced.</li>
248         </ul>
249     */
250     void                     SetFileName( const String& _rFileName );
251 
252     String                   GetCurrentFilter() const;
253     String                   GetDisplayDirectory() const;
254     ErrCode                  GetGraphic( Graphic& rGraphic ) const;
255 
256     ::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > GetFilePicker() const;
257 
258     // XFilePickerListener methods
259     virtual void SAL_CALL   FileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
260     virtual void SAL_CALL   DirectoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
261     virtual void SAL_CALL   ControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
262     virtual void SAL_CALL   DialogSizeChanged();
263     virtual ::rtl::OUString SAL_CALL    HelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
264 
265     // XDialogClosedListener methods
266     virtual void SAL_CALL   DialogClosed( const ::com::sun::star::ui::dialogs::DialogClosedEvent& _rEvent );
267 
268     // retrieves the top-most file picker - i.e. the instance which is currently beeing executed
269     static ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePicker >
270                             GetTopMostFilePicker( );
271 
272     /** sets help ids for the controls in the dialog
273         @param _pControlId
274             Pointer to a 0-terminated array of control ids. They must be recruited from the
275             CommonFilePickerElementIds and ExtendedFilePickerElementIds values.
276         @param _pHelpId
277             Pointer to an array of help ids. For each element in _pControlId, there must be
278             a corresponding element herein.
279     */
280     void                    SetControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
281     void                    CreateMatcher( const String& rName );
282 
283     /** sets the context of the dialog and trigger necessary actions e.g. loading config, setting help id
284         @param _eNewContext
285             New context for the dialog.
286     */
287     void                    SetContext( Context _eNewContext );
288 
289    DECL_LINK( ExecuteSystemFilePicker, void* );
290 
291 //#if 0 // _SOLAR__PRIVATE
292     ErrCode                  Execute( SvStringsDtor*& rpURLList,
293                                       SfxItemSet *&   rpSet,
294                                       String&         rFilter,
295                                       const String&   rDirPath );
296     ErrCode                  Execute( SfxItemSet *&   rpSet,
297                                       String&         rFilter );
298 //#endif
299 };
300 
301 #define SFX2_IMPL_DIALOG_CONFIG 0
302 #define SFX2_IMPL_DIALOG_SYSTEM 1
303 #define SFX2_IMPL_DIALOG_OOO 2
304 
305 //#if 0 // _SOLAR__PRIVATE
306 ErrCode FileOpenDialog_Impl( sal_Int64 nFlags,
307                              const String& rFact,
308                              SvStringsDtor *& rpURLList,
309                              String& rFilter,
310                              SfxItemSet *& rpSet,
311                              const String* pPath = NULL,
312                              sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG,
313                              const String& rStandardDir = String::CreateFromAscii( "" ),
314                              const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList = ::com::sun::star::uno::Sequence< ::rtl::OUString >());
315 //#endif
316 }
317 
318 //-----------------------------------------------------------------------------
319 
320 #endif
321 
322