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 OUStringLiteral FILEDIALOG_FILTER_ALL
= u
"*.*";
75 class FileDialogHelper_Impl
;
77 class SFX2_DLLPUBLIC FileDialogHelper
80 // context where the FileDialogHelper is used
102 DrawImpressInsertFile
,
103 DrawImpressOpenSound
,
122 ScreenshotAnnotation
,
125 WriterCreateAddressList
,
130 WriterImportAutotext
,
131 WriterInsertHyperlink
,
134 WriterMailMergeSaveAs
,
135 WriterNewHTMLGlobalDoc
,
136 WriterRegisterDataSource
,
141 static OUString
contextToString(Context context
);
144 Link
<FileDialogHelper
*,void> m_aDialogClosedLink
;
147 rtl::Reference
< FileDialogHelper_Impl
> mpImpl
;
151 FileDialogHelper(sal_Int16 nDialogType
,
152 FileDialogFlags nFlags
,
153 weld::Window
* pPreferredParent
);
155 FileDialogHelper(sal_Int16 nDialogType
,
156 FileDialogFlags nFlags
,
157 const OUString
& rFactory
,
158 SfxFilterFlags nMust
,
159 SfxFilterFlags nDont
,
160 weld::Window
* pPreferredParent
);
162 FileDialogHelper(sal_Int16 nDialogType
,
163 FileDialogFlags nFlags
,
164 const OUString
& rFactory
,
166 SfxFilterFlags nMust
,
167 SfxFilterFlags nDont
,
168 const OUString
& rStandardDir
,
169 const css::uno::Sequence
< OUString
>& rDenyList
,
170 weld::Window
* pPreferredParent
);
172 FileDialogHelper(sal_Int16 nDialogType
,
173 FileDialogFlags nFlags
,
174 const OUString
& aFilterUIName
,
175 std::u16string_view aExtName
,
176 const OUString
& rStandardDir
,
177 const css::uno::Sequence
< OUString
>& rDenyList
,
178 weld::Window
* pPreferredParent
);
180 virtual ~FileDialogHelper();
182 FileDialogHelper
& operator=(const FileDialogHelper
&) = delete;
183 FileDialogHelper(const FileDialogHelper
&) = delete;
186 void StartExecuteModal( const Link
<FileDialogHelper
*,void>& rEndDialogHdl
);
187 ErrCode
const & GetError() const { return m_nError
; }
188 sal_Int16
GetDialogType() const;
189 bool IsPasswordEnabled() const;
190 OUString
GetRealFilter() const;
192 void SetTitle( const OUString
& rNewTitle
);
193 OUString
GetPath() const;
195 /** @deprecated: Don't use this method to retrieve the selected files
196 There are file picker which can provide multiple selected file which belong
197 to different folders. As this method always provides the root folder for all selected
198 files this cannot work.
200 css::uno::Sequence
< OUString
> GetMPath() const;
202 /** Provides the selected files with full path information */
203 css::uno::Sequence
< OUString
> GetSelectedFiles() const;
205 void AddFilter( const OUString
& rFilterName
, const OUString
& rExtension
);
206 void SetCurrentFilter( const OUString
& rFilter
);
208 /** sets an initial display directory/file name
211 don't use this method. It contains a lot of magic in determining whether the
212 last segment of the given path/URL denotes a file name or a folder, and by
213 definition, it cannot succeed with this magic *all* the time - there will
214 always be scenarios where it fails.
216 Use SetDisplayFolder and SetFileName.
218 void SetDisplayDirectory( const OUString
& rPath
);
220 /** sets a new folder whose content is to be displayed in the file picker
223 specifies the URL of the folder whose content is to be displayed.<br/>
224 If the URL doesn't denote a valid (existent and accessible) folder, the
225 request is silently dropped.
226 @throws css::uno::RuntimeException
227 if the invocation of any of the file picker or UCB methods throws a RuntimeException.
229 void SetDisplayFolder( const OUString
& _rURL
);
231 /** sets an initial file name to display
233 This method is usually used in "save-as" contexts, where the application should
234 suggest an initial name for the file to save.
236 Calling this method is nearly equivalent to calling <code>GetFilePicker().setDefaultName( _rFileName )</code>,
237 with the following differences:
238 <ul><li>The FileDialogHelper remembers the given file name, and upon execution,
239 strips its extension if the dialog is set up for "automatic file name extension".</li>
240 <li>Exceptions thrown from the <code>XFilePicker3</code> are caught and silenced.</li>
243 void SetFileName( const OUString
& _rFileName
);
245 OUString
GetCurrentFilter() const;
246 OUString
GetDisplayDirectory() const;
247 ErrCode
GetGraphic( Graphic
& rGraphic
) const;
249 const css::uno::Reference
< css::ui::dialogs::XFilePicker3
>& GetFilePicker() const;
251 // XFilePickerListener methods
252 void FileSelectionChanged();
253 void DirectoryChanged();
254 virtual void ControlStateChanged( const css::ui::dialogs::FilePickerEvent
& aEvent
);
255 void DialogSizeChanged();
256 static OUString
HelpRequested( const css::ui::dialogs::FilePickerEvent
& aEvent
);
258 // XDialogClosedListener methods
259 void DialogClosed( const css::ui::dialogs::DialogClosedEvent
& _rEvent
);
261 /** sets help ids for the controls in the dialog
263 Pointer to a 0-terminated array of control ids. They must be recruited from the
264 CommonFilePickerElementIds and ExtendedFilePickerElementIds values.
266 Pointer to an array of help ids. For each element in _pControlId, there must be
267 a corresponding element herein.
269 void SetControlHelpIds( const sal_Int16
* _pControlId
, const char** _pHelpId
);
270 void CreateMatcher( const OUString
& rName
);
272 /** sets the context of the dialog and trigger necessary actions e.g. loading config, setting help id
273 This will also store the last used directory for this context, so that the last directory
274 gets preselected on next filepicker launch (with the same context)
276 New context for the dialog.
278 void SetContext( Context _eNewContext
);
280 DECL_DLLPRIVATE_LINK( ExecuteSystemFilePicker
, void*, void );
282 ErrCode
Execute( std::vector
<OUString
>& rpURLList
,
283 std::optional
<SfxAllItemSet
>& rpSet
,
285 const OUString
& rDirPath
);
286 ErrCode
Execute( std::optional
<SfxAllItemSet
>& rpSet
,
290 #define SFX2_IMPL_DIALOG_CONFIG 0
291 #define SFX2_IMPL_DIALOG_SYSTEM 1
292 #define SFX2_IMPL_DIALOG_OOO 2
293 #define SFX2_IMPL_DIALOG_REMOTE 3
295 ErrCode
FileOpenDialog_Impl( weld::Window
* pParent
,
296 sal_Int16 nDialogType
,
297 FileDialogFlags nFlags
,
298 std::vector
<OUString
>& rpURLList
,
300 std::optional
<SfxAllItemSet
>& rpSet
,
301 const OUString
* pPath
,
303 const OUString
& rStandardDir
,
304 const css::uno::Sequence
< OUString
>& rDenyList
= css::uno::Sequence
< OUString
>());
306 css::uno::Reference
<css::ui::dialogs::XFolderPicker2
> SFX2_DLLPUBLIC
createFolderPicker(const css::uno::Reference
<css::uno::XComponentContext
>& rContext
, weld::Window
* pPreferredParent
);
308 ErrCode
RequestPassword(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
, OUString
const & aURL
, SfxItemSet
* pSet
, const css::uno::Reference
<css::awt::XWindow
>& rParent
);
309 ErrCode
SetPassword(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
, SfxItemSet
* pSet
,
310 const OUString
& rPasswordToOpen
, std::u16string_view rPasswordToModify
,
311 bool bAllowPasswordReset
= false);
312 bool IsOOXML(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
);
313 bool IsMSType(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
);
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */