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>
26 #include <rtl/ref.hxx>
27 #include <rtl/ustring.hxx>
28 #include <comphelper/documentconstants.hxx>
29 #include <tools/link.hxx>
30 #include <vcl/errcode.hxx>
31 #include <o3tl/typed_flags_set.hxx>
36 namespace com::sun::star::ui::dialogs
39 struct FilePickerEvent
;
40 struct DialogClosedEvent
;
42 namespace com::sun::star::awt
{ class XWindow
; }
43 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
44 namespace weld
{ class Window
; }
50 enum class FileDialogFlags
{
52 Insert
= 0x01, // turn Open into Insert dialog
53 Export
= 0x02, // turn Save into Export dialog
54 SaveACopy
= 0x04, // turn Save into Save a Copy dialog
55 MultiSelection
= 0x08,
56 Graphic
= 0x10, // register graphic formats
57 /// Sign existing PDF.
59 InsertCompare
= 0x40, /// Special insertion ("Compare" caption)
60 InsertMerge
= 0x80, /// Special insertion ("Merge" caption)
63 template<> struct typed_flags
<FileDialogFlags
> : is_typed_flags
<FileDialogFlags
, 0xFF> {};
66 #define FILEDIALOG_FILTER_ALL "*.*"
70 class FileDialogHelper_Impl
;
72 class SFX2_DLLPUBLIC FileDialogHelper
75 enum Context
// context where the FileDialogHelper is used
77 UNKNOWN_CONTEXT
, // unknown context
78 SW_INSERT_GRAPHIC
, // insert graphic in writer
79 SD_EXPORT
, // export in draw
80 SI_EXPORT
, // export in impress
81 SW_EXPORT
// export in writer
85 Link
<FileDialogHelper
*,void> m_aDialogClosedLink
;
88 rtl::Reference
< FileDialogHelper_Impl
> mpImpl
;
92 FileDialogHelper(sal_Int16 nDialogType
,
93 FileDialogFlags nFlags
,
94 weld::Window
* pPreferredParent
);
96 FileDialogHelper(sal_Int16 nDialogType
,
97 FileDialogFlags nFlags
,
98 const OUString
& rFactory
,
100 SfxFilterFlags nDont
,
101 weld::Window
* pPreferredParent
);
103 FileDialogHelper(sal_Int16 nDialogType
,
104 FileDialogFlags nFlags
,
105 const OUString
& rFactory
,
107 SfxFilterFlags nMust
,
108 SfxFilterFlags nDont
,
109 const OUString
& rStandardDir
,
110 const css::uno::Sequence
< OUString
>& rDenyList
,
111 weld::Window
* pPreferredParent
);
113 FileDialogHelper(sal_Int16 nDialogType
,
114 FileDialogFlags nFlags
,
115 const OUString
& aFilterUIName
,
116 const OUString
& aExtName
,
117 const OUString
& rStandardDir
,
118 const css::uno::Sequence
< OUString
>& rDenyList
,
119 weld::Window
* pPreferredParent
);
121 virtual ~FileDialogHelper();
123 FileDialogHelper
& operator=(const FileDialogHelper
&) = delete;
124 FileDialogHelper(const FileDialogHelper
&) = delete;
127 void StartExecuteModal( const Link
<FileDialogHelper
*,void>& rEndDialogHdl
);
128 ErrCode
const & GetError() const { return m_nError
; }
129 sal_Int16
GetDialogType() const;
130 bool IsPasswordEnabled() const;
131 OUString
GetRealFilter() const;
133 void SetTitle( const OUString
& rNewTitle
);
134 OUString
GetPath() const;
136 /** @deprecated: Don't use this method to retrieve the selected files
137 There are file picker which can provide multiple selected file which belong
138 to different folders. As this method always provides the root folder for all selected
139 files this cannot work.
141 css::uno::Sequence
< OUString
> GetMPath() const;
143 /** Provides the selected files with full path information */
144 css::uno::Sequence
< OUString
> GetSelectedFiles() const;
146 void AddFilter( const OUString
& rFilterName
, const OUString
& rExtension
);
147 void SetCurrentFilter( const OUString
& rFilter
);
149 /** sets an initial display directory/file name
152 don't use this method. It contains a lot of magic in determining whether the
153 last segment of the given path/URL denotes a file name or a folder, and by
154 definition, it cannot succeed with this magic *all* the time - there will
155 always be scenarios where it fails.
157 Use SetDisplayFolder and SetFileName.
159 void SetDisplayDirectory( const OUString
& rPath
);
161 /** sets a new folder whose content is to be displayed in the file picker
164 specifies the URL of the folder whose content is to be displayed.<br/>
165 If the URL doesn't denote a valid (existent and accessible) folder, the
166 request is silently dropped.
167 @throws css::uno::RuntimeException
168 if the invocation of any of the file picker or UCB methods throws a RuntimeException.
170 void SetDisplayFolder( const OUString
& _rURL
);
172 /** sets an initial file name to display
174 This method is usually used in "save-as" contexts, where the application should
175 suggest an initial name for the file to save.
177 Calling this method is nearly equivalent to calling <code>GetFilePicker().setDefaultName( _rFileName )</code>,
178 with the following differences:
179 <ul><li>The FileDialogHelper remembers the given file name, and upon execution,
180 strips its extension if the dialog is set up for "automatic file name extension".</li>
181 <li>Exceptions thrown from the <code>XFilePicker3</code> are caught and silenced.</li>
184 void SetFileName( const OUString
& _rFileName
);
186 OUString
GetCurrentFilter() const;
187 OUString
GetDisplayDirectory() const;
188 ErrCode
GetGraphic( Graphic
& rGraphic
) const;
190 const css::uno::Reference
< css::ui::dialogs::XFilePicker3
>& GetFilePicker() const;
192 // XFilePickerListener methods
193 void FileSelectionChanged();
194 void DirectoryChanged();
195 virtual void ControlStateChanged( const css::ui::dialogs::FilePickerEvent
& aEvent
);
196 void DialogSizeChanged();
197 static OUString
HelpRequested( const css::ui::dialogs::FilePickerEvent
& aEvent
);
199 // XDialogClosedListener methods
200 void DialogClosed( const css::ui::dialogs::DialogClosedEvent
& _rEvent
);
202 /** sets help ids for the controls in the dialog
204 Pointer to a 0-terminated array of control ids. They must be recruited from the
205 CommonFilePickerElementIds and ExtendedFilePickerElementIds values.
207 Pointer to an array of help ids. For each element in _pControlId, there must be
208 a corresponding element herein.
210 void SetControlHelpIds( const sal_Int16
* _pControlId
, const char** _pHelpId
);
211 void CreateMatcher( const OUString
& rName
);
213 /** sets the context of the dialog and trigger necessary actions e.g. loading config, setting help id
215 New context for the dialog.
217 void SetContext( Context _eNewContext
);
219 DECL_LINK( ExecuteSystemFilePicker
, void*, void );
221 ErrCode
Execute( std::vector
<OUString
>& rpURLList
,
222 std::unique_ptr
<SfxItemSet
>& rpSet
,
224 const OUString
& rDirPath
);
225 ErrCode
Execute( std::unique_ptr
<SfxItemSet
>& rpSet
,
229 #define SFX2_IMPL_DIALOG_CONFIG 0
230 #define SFX2_IMPL_DIALOG_SYSTEM 1
231 #define SFX2_IMPL_DIALOG_OOO 2
232 #define SFX2_IMPL_DIALOG_REMOTE 3
234 ErrCode
FileOpenDialog_Impl( weld::Window
* pParent
,
235 sal_Int16 nDialogType
,
236 FileDialogFlags nFlags
,
237 std::vector
<OUString
>& rpURLList
,
239 std::unique_ptr
<SfxItemSet
>& rpSet
,
240 const OUString
* pPath
,
242 const OUString
& rStandardDir
,
243 const css::uno::Sequence
< OUString
>& rDenyList
= css::uno::Sequence
< OUString
>());
246 ErrCode
RequestPassword(const std::shared_ptr
<const SfxFilter
>& pCurrentFilter
, OUString
const & aURL
, SfxItemSet
* pSet
, const css::uno::Reference
<css::awt::XWindow
>& rParent
);
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */