lok: calc - send other views our selection in their co-ordinates.
[LibreOffice.git] / include / sfx2 / filedlghelper.hxx
blob42d6b53c0cfb0e8fe0ff531558e1f9aa7dc1b534
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
33 #include <memory>
34 #include <vector>
36 namespace com
38 namespace sun
40 namespace star
42 namespace ui
44 namespace dialogs
46 class XFilePicker3;
47 struct FilePickerEvent;
48 struct DialogClosedEvent;
55 namespace com::sun::star::awt { class XWindow; }
56 namespace com::sun::star::uno { template <typename > class Reference; }
57 namespace weld { class Window; }
59 class Graphic;
60 class SfxFilter;
61 class SfxItemSet;
63 enum class FileDialogFlags {
64 NONE = 0x00,
65 Insert = 0x01, // turn Open into Insert dialog
66 Export = 0x02, // turn Save into Export dialog
67 SaveACopy = 0x04, // turn Save into Save a Copy dialog
68 MultiSelection = 0x08,
69 Graphic = 0x10, // register graphic formats
70 /// Sign existing PDF.
71 SignPDF = 0x20,
72 InsertCompare = 0x40, /// Special insertion ("Compare" caption)
73 InsertMerge = 0x80, /// Special insertion ("Merge" caption)
75 namespace o3tl {
76 template<> struct typed_flags<FileDialogFlags> : is_typed_flags<FileDialogFlags, 0xFF> {};
79 #define FILEDIALOG_FILTER_ALL "*.*"
81 namespace sfx2 {
83 class FileDialogHelper_Impl;
85 class SFX2_DLLPUBLIC FileDialogHelper
87 public:
88 enum Context // context where the FileDialogHelper is used
90 UNKNOWN_CONTEXT, // unknown context
91 SW_INSERT_GRAPHIC, // insert graphic in writer
92 SD_EXPORT, // export in draw
93 SI_EXPORT, // export in impress
94 SW_EXPORT // export in writer
97 private:
98 Link<FileDialogHelper*,void> m_aDialogClosedLink;
99 ErrCode m_nError;
101 rtl::Reference< FileDialogHelper_Impl > mpImpl;
104 public:
105 FileDialogHelper(sal_Int16 nDialogType,
106 FileDialogFlags nFlags,
107 weld::Window* pPreferredParent);
109 FileDialogHelper(sal_Int16 nDialogType,
110 FileDialogFlags nFlags,
111 const OUString& rFactory,
112 SfxFilterFlags nMust,
113 SfxFilterFlags nDont,
114 weld::Window* pPreferredParent);
116 FileDialogHelper(sal_Int16 nDialogType,
117 FileDialogFlags nFlags,
118 const OUString& rFactory,
119 sal_Int16 nDialog,
120 SfxFilterFlags nMust,
121 SfxFilterFlags nDont,
122 const OUString& rStandardDir,
123 const css::uno::Sequence< OUString >& rBlackList,
124 weld::Window* pPreferredParent);
126 FileDialogHelper(sal_Int16 nDialogType,
127 FileDialogFlags nFlags,
128 const OUString& aFilterUIName,
129 const OUString& aExtName,
130 const OUString& rStandardDir,
131 const css::uno::Sequence< OUString >& rBlackList,
132 weld::Window* pPreferredParent);
134 virtual ~FileDialogHelper();
136 FileDialogHelper& operator=(const FileDialogHelper &) = delete;
137 FileDialogHelper(const FileDialogHelper &) = delete;
139 ErrCode Execute();
140 void StartExecuteModal( const Link<FileDialogHelper*,void>& rEndDialogHdl );
141 ErrCode const & GetError() const { return m_nError; }
142 sal_Int16 GetDialogType() const;
143 bool IsPasswordEnabled() const;
144 OUString GetRealFilter() const;
146 void SetTitle( const OUString& rNewTitle );
147 OUString GetPath() const;
149 /** @deprecated: Don't use this method to retrieve the selected files
150 There are file picker which can provide multiple selected file which belong
151 to different folders. As this method always provides the root folder for all selected
152 files this cannot work.
154 css::uno::Sequence< OUString > GetMPath() const;
156 /** Provides the selected files with full path information */
157 css::uno::Sequence< OUString > GetSelectedFiles() const;
159 void AddFilter( const OUString& rFilterName, const OUString& rExtension );
160 void SetCurrentFilter( const OUString& rFilter );
162 /** sets an initial display directory/file name
164 @deprecated
165 don't use this method. It contains a lot of magic in determining whether the
166 last segment of the given path/URL denotes a file name or a folder, and by
167 definition, it cannot succeed with this magic *all* the time - there will
168 always be scenarios where it fails.
170 Use SetDisplayFolder and SetFileName.
172 void SetDisplayDirectory( const OUString& rPath );
174 /** sets a new folder whose content is to be displayed in the file picker
176 @param _rURL
177 specifies the URL of the folder whose content is to be displayed.<br/>
178 If the URL doesn't denote a valid (existent and accessible) folder, the
179 request is silently dropped.
180 @throws css::uno::RuntimeException
181 if the invocation of any of the file picker or UCB methods throws a RuntimeException.
183 void SetDisplayFolder( const OUString& _rURL );
185 /** sets an initial file name to display
187 This method is usually used in "save-as" contexts, where the application should
188 suggest an initial name for the file to save.
190 Calling this method is nearly equivalent to calling <code>GetFilePicker().setDefaultName( _rFileName )</code>,
191 with the following differences:
192 <ul><li>The FileDialogHelper remembers the given file name, and upon execution,
193 strips its extension if the dialog is set up for "automatic file name extension".</li>
194 <li>Exceptions thrown from the <code>XFilePicker3</code> are caught and silenced.</li>
195 </ul>
197 void SetFileName( const OUString& _rFileName );
199 OUString GetCurrentFilter() const;
200 OUString GetDisplayDirectory() const;
201 ErrCode GetGraphic( Graphic& rGraphic ) const;
203 const css::uno::Reference < css::ui::dialogs::XFilePicker3 >& GetFilePicker() const;
205 // XFilePickerListener methods
206 void FileSelectionChanged();
207 void DirectoryChanged();
208 virtual void ControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent );
209 void DialogSizeChanged();
210 static OUString HelpRequested( const css::ui::dialogs::FilePickerEvent& aEvent );
212 // XDialogClosedListener methods
213 void DialogClosed( const css::ui::dialogs::DialogClosedEvent& _rEvent );
215 /** sets help ids for the controls in the dialog
216 @param _pControlId
217 Pointer to a 0-terminated array of control ids. They must be recruited from the
218 CommonFilePickerElementIds and ExtendedFilePickerElementIds values.
219 @param _pHelpId
220 Pointer to an array of help ids. For each element in _pControlId, there must be
221 a corresponding element herein.
223 void SetControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
224 void CreateMatcher( const OUString& rName );
226 /** sets the context of the dialog and trigger necessary actions e.g. loading config, setting help id
227 @param _eNewContext
228 New context for the dialog.
230 void SetContext( Context _eNewContext );
232 DECL_LINK( ExecuteSystemFilePicker, void*, void );
234 ErrCode Execute( std::vector<OUString>& rpURLList,
235 std::unique_ptr<SfxItemSet>& rpSet,
236 OUString& rFilter,
237 const OUString& rDirPath );
238 ErrCode Execute( std::unique_ptr<SfxItemSet>& rpSet,
239 OUString& rFilter );
242 #define SFX2_IMPL_DIALOG_CONFIG 0
243 #define SFX2_IMPL_DIALOG_SYSTEM 1
244 #define SFX2_IMPL_DIALOG_OOO 2
245 #define SFX2_IMPL_DIALOG_REMOTE 3
247 ErrCode FileOpenDialog_Impl( weld::Window* pParent,
248 sal_Int16 nDialogType,
249 FileDialogFlags nFlags,
250 std::vector<OUString>& rpURLList,
251 OUString& rFilter,
252 std::unique_ptr<SfxItemSet>& rpSet,
253 const OUString* pPath,
254 sal_Int16 nDialog,
255 const OUString& rStandardDir,
256 const css::uno::Sequence< OUString >& rBlackList = css::uno::Sequence< OUString >());
259 ErrCode RequestPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, OUString const & aURL, SfxItemSet* pSet, const css::uno::Reference<css::awt::XWindow>& rParent);
262 #endif
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */