/src/libreoffice/include/sfx2/filedlghelper.hxx
Line | Count | Source |
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_SFX2_FILEDLGHELPER_HXX |
20 | | #define INCLUDED_SFX2_FILEDLGHELPER_HXX |
21 | | |
22 | | #include <sal/config.h> |
23 | | #include <sfx2/dllapi.h> |
24 | | #include <sal/types.h> |
25 | | #include <com/sun/star/uno/Sequence.hxx> |
26 | | |
27 | | #include <rtl/ref.hxx> |
28 | | #include <rtl/ustring.hxx> |
29 | | #include <comphelper/documentconstants.hxx> |
30 | | #include <tools/link.hxx> |
31 | | #include <comphelper/errcode.hxx> |
32 | | #include <o3tl/typed_flags_set.hxx> |
33 | | #include <vcl/weld/Dialog.hxx> |
34 | | |
35 | | #include <memory> |
36 | | #include <optional> |
37 | | |
38 | | namespace com::sun::star::ui::dialogs |
39 | | { |
40 | | class XFilePicker3; |
41 | | class XFolderPicker2; |
42 | | struct FilePickerEvent; |
43 | | struct DialogClosedEvent; |
44 | | } |
45 | | namespace com::sun::star::awt { class XWindow; } |
46 | | namespace com::sun::star::uno { template <typename > class Reference; } |
47 | | namespace com::sun::star::uno { class XComponentContext; } |
48 | | namespace weld { class Window; } |
49 | | |
50 | | enum class SignatureState; |
51 | | class Graphic; |
52 | | class SfxFilter; |
53 | | class SfxItemSet; |
54 | | class SfxAllItemSet; |
55 | | |
56 | | enum class FileDialogFlags { |
57 | | NONE = 0x00, |
58 | | Insert = 0x01, // turn Open into Insert dialog |
59 | | Export = 0x02, // turn Save into Export dialog |
60 | | SaveACopy = 0x04, // turn Save into Save a Copy dialog |
61 | | MultiSelection = 0x08, |
62 | | Graphic = 0x10, // register graphic formats |
63 | | /// Sign existing PDF. |
64 | | SignPDF = 0x20, |
65 | | InsertCompare = 0x40, /// Special insertion ("Compare" caption) |
66 | | InsertMerge = 0x80, /// Special insertion ("Merge" caption) |
67 | | }; |
68 | | namespace o3tl { |
69 | | template<> struct typed_flags<FileDialogFlags> : is_typed_flags<FileDialogFlags, 0xFF> {}; |
70 | | } |
71 | | |
72 | | inline constexpr OUString FILEDIALOG_FILTER_ALL = u"*.*"_ustr; |
73 | | |
74 | | namespace sfx2 { |
75 | | |
76 | | class FileDialogHelper_Impl; |
77 | | |
78 | | class SFX2_DLLPUBLIC FileDialogHelper |
79 | | { |
80 | | public: |
81 | | // context where the FileDialogHelper is used |
82 | | enum Context |
83 | | { |
84 | | UnknownContext, |
85 | | AcceleratorConfig, |
86 | | AutoRedact, |
87 | | BaseDataSource, |
88 | | BaseSaveAs, |
89 | | BasicExportPackage, |
90 | | BasicExportDialog, |
91 | | BasicExportSource, |
92 | | BasicImportDialog, |
93 | | BasicImportSource, |
94 | | BasicInsertLib, |
95 | | BulletsAddImage, |
96 | | ExtensionManager, |
97 | | CalcDataProvider, |
98 | | CalcDataStream, |
99 | | CalcExport, |
100 | | CalcSaveAs, |
101 | | CalcXMLSource, |
102 | | DrawExport, |
103 | | DrawImpressInsertFile, |
104 | | DrawImpressOpenSound, |
105 | | DrawSaveAs, |
106 | | ExportImage, |
107 | | FormsAddInstance, |
108 | | FormsInsertImage, |
109 | | IconImport, |
110 | | ImpressClickAction, |
111 | | ImpressExport, |
112 | | ImpressPhotoDialog, |
113 | | ImpressSaveAs, |
114 | | LinkClientOLE, |
115 | | LinkClientFile, |
116 | | ImageMap, |
117 | | InsertDoc, |
118 | | InsertImage, |
119 | | InsertMedia, |
120 | | InsertOLE, |
121 | | JavaClassPath, |
122 | | ReportInsertImage, |
123 | | ScreenshotAnnotation, |
124 | | SignatureLine, |
125 | | TemplateImport, |
126 | | WriterCreateAddressList, |
127 | | WriterInsertImage, |
128 | | WriterInsertScript, |
129 | | WriterExport, |
130 | | WriterImportAutotext, |
131 | | WriterLoadTemplate, |
132 | | WriterMailMerge, |
133 | | WriterMailMergeSaveAs, |
134 | | WriterNewHTMLGlobalDoc, |
135 | | WriterRegisterDataSource, |
136 | | WriterSaveAs, |
137 | | WriterSaveHTML, |
138 | | XMLFilterSettings |
139 | | }; |
140 | | static OUString contextToString(Context context); |
141 | | |
142 | | private: |
143 | | Link<FileDialogHelper*,void> m_aDialogClosedLink; |
144 | | ErrCode m_nError; |
145 | | |
146 | | rtl::Reference< FileDialogHelper_Impl > mpImpl; |
147 | | |
148 | | |
149 | | public: |
150 | | FileDialogHelper(sal_Int16 nDialogType, |
151 | | FileDialogFlags nFlags, |
152 | | weld::Window* pPreferredParent); |
153 | | |
154 | | FileDialogHelper(sal_Int16 nDialogType, |
155 | | FileDialogFlags nFlags, |
156 | | const OUString& rFactory, |
157 | | SfxFilterFlags nMust, |
158 | | SfxFilterFlags nDont, |
159 | | weld::Window* pPreferredParent); |
160 | | |
161 | | FileDialogHelper(sal_Int16 nDialogType, |
162 | | FileDialogFlags nFlags, |
163 | | const OUString& rFactory, |
164 | | sal_Int16 nDialog, |
165 | | SfxFilterFlags nMust, |
166 | | SfxFilterFlags nDont, |
167 | | const OUString& rPreselectedDir, |
168 | | const css::uno::Sequence< OUString >& rDenyList, |
169 | | weld::Window* pPreferredParent); |
170 | | |
171 | | FileDialogHelper(sal_Int16 nDialogType, |
172 | | FileDialogFlags nFlags, |
173 | | const OUString& aFilterUIName, |
174 | | std::u16string_view aExtName, |
175 | | const OUString& rPreselectedDir, |
176 | | const css::uno::Sequence< OUString >& rDenyList, |
177 | | weld::Window* pPreferredParent); |
178 | | |
179 | | virtual ~FileDialogHelper(); |
180 | | |
181 | | FileDialogHelper& operator=(const FileDialogHelper &) = delete; |
182 | | FileDialogHelper(const FileDialogHelper &) = delete; |
183 | | |
184 | | ErrCode Execute(); |
185 | | void StartExecuteModal( const Link<FileDialogHelper*,void>& rEndDialogHdl ); |
186 | 0 | ErrCode const & GetError() const { return m_nError; } |
187 | | sal_Int16 GetDialogType() const; |
188 | | bool IsPasswordEnabled() const; |
189 | | OUString GetRealFilter() const; |
190 | | bool CheckCurrentFilterOptionsCapability() const; |
191 | | |
192 | | void SetTitle( const OUString& rNewTitle ); |
193 | | OUString GetPath() const; |
194 | | |
195 | | /** Provides the selected files with full path information */ |
196 | | css::uno::Sequence< OUString > GetSelectedFiles() const; |
197 | | |
198 | | void AddFilter( const OUString& rFilterName, const OUString& rExtension ); |
199 | | void SetCurrentFilter( const OUString& rFilter ); |
200 | | |
201 | | /** sets an initial display directory/file name |
202 | | |
203 | | @deprecated |
204 | | don't use this method. It contains a lot of magic in determining whether the |
205 | | last segment of the given path/URL denotes a file name or a folder, and by |
206 | | definition, it cannot succeed with this magic *all* the time - there will |
207 | | always be scenarios where it fails. |
208 | | |
209 | | Use SetDisplayFolder and SetFileName. |
210 | | */ |
211 | | void SetDisplayDirectory( const OUString& rPath ); |
212 | | |
213 | | /** sets a new folder whose content is to be displayed in the file picker |
214 | | |
215 | | @param _rURL |
216 | | specifies the URL of the folder whose content is to be displayed.<br/> |
217 | | If the URL doesn't denote a valid (existent and accessible) folder, the |
218 | | request is silently dropped. |
219 | | @throws css::uno::RuntimeException |
220 | | if the invocation of any of the file picker or UCB methods throws a RuntimeException. |
221 | | */ |
222 | | void SetDisplayFolder( const OUString& _rURL ); |
223 | | |
224 | | /** sets an initial file name to display |
225 | | |
226 | | This method is usually used in "save-as" contexts, where the application should |
227 | | suggest an initial name for the file to save. |
228 | | |
229 | | Calling this method is nearly equivalent to calling <code>GetFilePicker().setDefaultName( _rFileName )</code>, |
230 | | with the following differences: |
231 | | <ul><li>The FileDialogHelper remembers the given file name, and upon execution, |
232 | | strips its extension if the dialog is set up for "automatic file name extension".</li> |
233 | | <li>Exceptions thrown from the <code>XFilePicker3</code> are caught and silenced.</li> |
234 | | </ul> |
235 | | */ |
236 | | void SetFileName( const OUString& _rFileName ); |
237 | | |
238 | | OUString GetCurrentFilter() const; |
239 | | OUString GetDisplayDirectory() const; |
240 | | ErrCode GetGraphic( Graphic& rGraphic ) const; |
241 | | |
242 | | const css::uno::Reference < css::ui::dialogs::XFilePicker3 >& GetFilePicker() const; |
243 | | |
244 | | // XFilePickerListener methods |
245 | | void FileSelectionChanged(); |
246 | | void DirectoryChanged(); |
247 | | virtual void ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent ); |
248 | | void DialogSizeChanged(); |
249 | | static OUString HelpRequested( const css::ui::dialogs::FilePickerEvent& aEvent ); |
250 | | |
251 | | // XDialogClosedListener methods |
252 | | void DialogClosed( const css::ui::dialogs::DialogClosedEvent& _rEvent ); |
253 | | |
254 | | /** sets help ids for the controls in the dialog |
255 | | @param _pControlId |
256 | | Pointer to a 0-terminated array of control ids. They must be recruited from the |
257 | | CommonFilePickerElementIds and ExtendedFilePickerElementIds values. |
258 | | @param _pHelpId |
259 | | Pointer to an array of help ids. For each element in _pControlId, there must be |
260 | | a corresponding element herein. |
261 | | */ |
262 | | void SetControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId ); |
263 | | void CreateMatcher( const OUString& rName ); |
264 | | |
265 | | /** sets the context of the dialog and trigger necessary actions e.g. loading config, setting help id |
266 | | This will also store the last used directory for this context, so that the last directory |
267 | | gets preselected on next filepicker launch (with the same context) |
268 | | @param _eNewContext |
269 | | New context for the dialog. |
270 | | */ |
271 | | void SetContext( Context _eNewContext ); |
272 | | |
273 | | DECL_DLLPRIVATE_LINK( ExecuteSystemFilePicker, void*, void ); |
274 | | |
275 | | ErrCode Execute( css::uno::Sequence<OUString>& rpURLList, |
276 | | std::optional<SfxAllItemSet>& rpSet, |
277 | | OUString& rFilter, |
278 | | const OUString& rDirPath ); |
279 | | ErrCode Execute( std::optional<SfxAllItemSet>& rpSet, |
280 | | OUString& rFilter, |
281 | | SignatureState nScriptingSignatureState); |
282 | | }; |
283 | | |
284 | 0 | #define SFX2_IMPL_DIALOG_CONFIG 0 |
285 | 0 | #define SFX2_IMPL_DIALOG_SYSTEM 1 |
286 | 0 | #define SFX2_IMPL_DIALOG_OOO 2 |
287 | 0 | #define SFX2_IMPL_DIALOG_REMOTE 3 |
288 | | |
289 | | ErrCode FileOpenDialog_Impl( weld::Window* pParent, |
290 | | sal_Int16 nDialogType, |
291 | | FileDialogFlags nFlags, |
292 | | css::uno::Sequence<OUString>& rpURLList, |
293 | | OUString& rFilter, |
294 | | std::optional<SfxAllItemSet>& rpSet, |
295 | | const OUString* pPath, |
296 | | sal_Int16 nDialog, |
297 | | const css::uno::Sequence< OUString >& rDenyList, |
298 | | std::optional<bool>& rShowFilterDialog ); |
299 | | |
300 | | css::uno::Reference<css::ui::dialogs::XFolderPicker2> SFX2_DLLPUBLIC createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>& rContext, weld::Window* pPreferredParent); |
301 | | |
302 | | ErrCode RequestPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, OUString const & aURL, SfxItemSet* pSet, const css::uno::Reference<css::awt::XWindow>& rParent); |
303 | | ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, SfxItemSet* pSet, |
304 | | const OUString& rPasswordToOpen, std::u16string_view rPasswordToModify, |
305 | | bool bAllowPasswordReset = false); |
306 | | bool IsOOXML(const std::shared_ptr<const SfxFilter>& pCurrentFilter); |
307 | | bool IsMSType(const std::shared_ptr<const SfxFilter>& pCurrentFilter); |
308 | | } |
309 | | |
310 | | #endif |
311 | | |
312 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |