1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SFX2_FILEDLGHELPER_HXX
20 #define INCLUDED_SFX2_FILEDLGHELPER_HXX
22 #include <sal/config.h>
23 #include <sfx2/dllapi.h>
24 #include <sal/types.h>
25 #include <com/sun/star/uno/Sequence.hxx>
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>
38 namespace com::sun::star::ui::dialogs
42 struct FilePickerEvent
;
43 struct DialogClosedEvent
;
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
; }
55 enum class FileDialogFlags
{
57 Insert
= 0x01, // turn Open into Insert dialog
58 Export
= 0x02, // turn Save into Export dialog
59 SaveACopy
= 0x04, // turn Save into Save a Copy dialog
60 MultiSelection
= 0x08,
61 Graphic
= 0x10, // register graphic formats
62 /// Sign existing PDF.
64 InsertCompare
= 0x40, /// Special insertion ("Compare" caption)
65 InsertMerge
= 0x80, /// Special insertion ("Merge" caption)
68 template<> struct typed_flags
<FileDialogFlags
> : is_typed_flags
<FileDialogFlags
, 0xFF> {};
71 inline constexpr OUString FILEDIALOG_FILTER_ALL
= u
"*.*"_ustr
;
75 class FileDialogHelper_Impl
;
77 class SFX2_DLLPUBLIC FileDialogHelper
80 // context where the FileDialogHelper is used
102 DrawImpressInsertFile
,
103 DrawImpressOpenSound
,
122 ScreenshotAnnotation
,
125 WriterCreateAddressList
,
129 WriterImportAutotext
,
130 WriterInsertHyperlink
,
133 WriterMailMergeSaveAs
,
134 WriterNewHTMLGlobalDoc
,
135 WriterRegisterDataSource
,
140 static OUString
contextToString(Context context
);
143 Link
<FileDialogHelper
*,void> m_aDialogClosedLink
;
146 rtl::Reference
< FileDialogHelper_Impl
> mpImpl
;
150 FileDialogHelper(sal_Int16 nDialogType
,
151 FileDialogFlags nFlags
,
152 weld::Window
* pPreferredParent
);
154 FileDialogHelper(sal_Int16 nDialogType
,
155 FileDialogFlags nFlags
,
156 const OUString
& rFactory
,
157 SfxFilterFlags nMust
,
158 SfxFilterFlags nDont
,
159 weld::Window
* pPreferredParent
);
161 FileDialogHelper(sal_Int16 nDialogType
,
162 FileDialogFlags nFlags
,
163 const OUString
& rFactory
,
165 SfxFilterFlags nMust
,
166 SfxFilterFlags nDont
,
167 const OUString
& rStandardDir
,
168 const css::uno::Sequence
< OUString
>& rDenyList
,
169 weld::Window
* pPreferredParent
);
171 FileDialogHelper(sal_Int16 nDialogType
,
172 FileDialogFlags nFlags
,
173 const OUString
& aFilterUIName
,
174 std::u16string_view aExtName
,
175 const OUString
& rStandardDir
,
176 const css::uno::Sequence
< OUString
>& rDenyList
,
177 weld::Window
* pPreferredParent
);
179 virtual ~FileDialogHelper();
181 FileDialogHelper
& operator=(const FileDialogHelper
&) = delete;
182 FileDialogHelper(const FileDialogHelper
&) = delete;
185 void StartExecuteModal( const Link
<FileDialogHelper
*,void>& rEndDialogHdl
);
186 ErrCode
const & GetError() const { return m_nError
; }
187 sal_Int16
GetDialogType() const;
188 bool IsPasswordEnabled() const;
189 OUString
GetRealFilter() const;
191 void SetTitle( const OUString
& rNewTitle
);
192 OUString
GetPath() const;
194 /** @deprecated: Don't use this method to retrieve the selected files
195 There are file picker which can provide multiple selected file which belong
196 to different folders. As this method always provides the root folder for all selected
197 files this cannot work.
199 css::uno::Sequence
< OUString
> GetMPath() const;
201 /** Provides the selected files with full path information */
202 css::uno::Sequence
< OUString
> GetSelectedFiles() const;
204 void AddFilter( const OUString
& rFilterName
, const OUString
& rExtension
);
205 void SetCurrentFilter( const OUString
& rFilter
);
207 /** sets an initial display directory/file name
210 don't use this method. It contains a lot of magic in determining whether the
211 last segment of the given path/URL denotes a file name or a folder, and by
212 definition, it cannot succeed with this magic *all* the time - there will
213 always be scenarios where it fails.
215 Use SetDisplayFolder and SetFileName.
217 void SetDisplayDirectory( const OUString
& rPath
);
219 /** sets a new folder whose content is to be displayed in the file picker
222 specifies the URL of the folder whose content is to be displayed.<br/>
223 If the URL doesn't denote a valid (existent and accessible) folder, the
224 request is silently dropped.
225 @throws css::uno::RuntimeException
226 if the invocation of any of the file picker or UCB methods throws a RuntimeException.
228 void SetDisplayFolder( const OUString
& _rURL
);
230 /** sets an initial file name to display
232 This method is usually used in "save-as" contexts, where the application should
233 suggest an initial name for the file to save.
235 Calling this method is nearly equivalent to calling <code>GetFilePicker().setDefaultName( _rFileName )</code>,
236 with the following differences:
237 <ul><li>The FileDialogHelper remembers the given file name, and upon execution,
238 strips its extension if the dialog is set up for "automatic file name extension".</li>
239 <li>Exceptions thrown from the <code>XFilePicker3</code> are caught and silenced.</li>
242 void SetFileName( const OUString
& _rFileName
);
244 OUString
GetCurrentFilter() const;
245 OUString
GetDisplayDirectory() const;
246 ErrCode
GetGraphic( Graphic
& rGraphic
) const;
248 const css::uno::Reference
< css::ui::dialogs::XFilePicker3
>& GetFilePicker() const;
250 // XFilePickerListener methods
251 void FileSelectionChanged();
252 void DirectoryChanged();
253 virtual void ControlStateChanged( const css::ui::dialogs::FilePickerEvent
& aEvent
);
254 void DialogSizeChanged();
255 static OUString
HelpRequested( const css::ui::dialogs::FilePickerEvent
& aEvent
);
257 // XDialogClosedListener methods
258 void DialogClosed( const css::ui::dialogs::DialogClosedEvent
& _rEvent
);
260 /** sets help ids for the controls in the dialog
262 Pointer to a 0-terminated array of control ids. They must be recruited from the
263 CommonFilePickerElementIds and ExtendedFilePickerElementIds values.
265 Pointer to an array of help ids. For each element in _pControlId, there must be
266 a corresponding element herein.
268 void SetControlHelpIds( const sal_Int16
* _pControlId
, const char** _pHelpId
);
269 void CreateMatcher( const OUString
& rName
);
271 /** sets the context of the dialog and trigger necessary actions e.g. loading config, setting help id
272 This will also store the last used directory for this context, so that the last directory
273 gets preselected on next filepicker launch (with the same context)
275 New context for the dialog.
277 void SetContext( Context _eNewContext
);
279 DECL_DLLPRIVATE_LINK( ExecuteSystemFilePicker
, void*, void );
281 ErrCode
Execute( std::vector
<OUString
>& rpURLList
,
282 std::optional
<SfxAllItemSet
>& rpSet
,
284 const OUString
& rDirPath
);
285 ErrCode
Execute( std::optional
<SfxAllItemSet
>& rpSet
,
289 #define SFX2_IMPL_DIALOG_CONFIG 0
290 #define SFX2_IMPL_DIALOG_SYSTEM 1
291 #define SFX2_IMPL_DIALOG_OOO 2
292 #define SFX2_IMPL_DIALOG_REMOTE 3
294 ErrCode
FileOpenDialog_Impl( weld::Window
* pParent
,
295 sal_Int16 nDialogType
,
296 FileDialogFlags nFlags
,
297 std::vector
<OUString
>& rpURLList
,
299 std::optional
<SfxAllItemSet
>& rpSet
,
300 const OUString
* pPath
,
302 const OUString
& rStandardDir
,
303 const css::uno::Sequence
< OUString
>& rDenyList
= css::uno::Sequence
< OUString
>());
305 css::uno::Reference
<css::ui::dialogs::XFolderPicker2
> SFX2_DLLPUBLIC
createFolderPicker(const css::uno::Reference
<css::uno::XComponentContext
>& rContext
, weld::Window
* pPreferredParent
);
307 ErrCode
RequestPassword(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
, OUString
const & aURL
, SfxItemSet
* pSet
, const css::uno::Reference
<css::awt::XWindow
>& rParent
);
308 ErrCode
SetPassword(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
, SfxItemSet
* pSet
,
309 const OUString
& rPasswordToOpen
, std::u16string_view rPasswordToModify
,
310 bool bAllowPasswordReset
= false);
311 bool IsOOXML(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
);
312 bool IsMSType(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
);
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */