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/Reference.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <rtl/ustring.hxx>
28 #include <tools/solar.h>
29 #include <tools/errcode.hxx>
30 #include <vcl/dialog.hxx>
31 #include <vcl/edit.hxx>
32 #include <vcl/button.hxx>
33 #include <vcl/graph.hxx>
34 #include <sfx2/sfxdefs.hxx>
35 #include <sfx2/sfxuno.hxx>
36 #include <sfx2/docfilt.hxx>
38 //-----------------------------------------------------------------------------
51 class XFilePickerListener
;
52 struct FilePickerEvent
;
53 struct DialogClosedEvent
;
63 // the SFXWB constants are for the nFlags parameter of the constructor
64 #define SFXWB_INSERT 0x04000000L // turn Open into Insert dialog
65 #define SFXWB_EXPORT 0x40000000L // turn Save into Export dialog
66 #define SFXWB_SAVEACOPY 0x00400000L // turn Save into Save a Copy dialog
67 #define SFXWB_MULTISELECTION 0x20000000L
68 #define SFXWB_GRAPHIC 0x00800000L // register graphic formats
70 #define FILEDIALOG_FILTER_ALL "*.*"
72 #define FILE_OPEN_SERVICE_NAME_OOO "com.sun.star.ui.dialogs.OfficeFilePicker"
76 class FileDialogHelper_Impl
;
78 class SFX2_DLLPUBLIC FileDialogHelper
81 enum Context
// context where the FileDialogHelper is used
83 UNKNOWN_CONTEXT
, // unknown context
84 SW_INSERT_GRAPHIC
, // insert graphic in writer
85 SW_INSERT_SOUND
, // insert sound in writer
86 SW_INSERT_VIDEO
, // insert video in writer
87 SC_INSERT_GRAPHIC
, // insert graphic in calc
88 SC_INSERT_SOUND
, // insert sound in calc
89 SC_INSERT_VIDEO
, // insert video in calc
90 SD_INSERT_GRAPHIC
, // insert graphic in draw
91 SD_INSERT_SOUND
, // insert sound in draw
92 SD_INSERT_VIDEO
, // insert video in draw
93 SD_EXPORT
, // export in draw
94 SI_EXPORT
, // export in impress
95 SW_EXPORT
// export in writer
99 Link m_aDialogClosedLink
;
102 ::com::sun::star::uno::Reference
< ::com::sun::star::ui::dialogs::XFilePickerListener
> mxImp
;
103 FileDialogHelper_Impl
*mpImp
;
107 FileDialogHelper( sal_Int16 nDialogType
,
109 Window
* _pPreferredParent
= NULL
);
111 FileDialogHelper( sal_Int16 nDialogType
,
113 const OUString
& rFactory
,
114 SfxFilterFlags nMust
= 0,
115 SfxFilterFlags nDont
= 0 );
117 FileDialogHelper( sal_Int16 nDialogType
,
119 const OUString
& rFactory
,
121 SfxFilterFlags nMust
,
122 SfxFilterFlags nDont
,
123 const OUString
& rStandardDir
,
124 const ::com::sun::star::uno::Sequence
< OUString
>& rBlackList
);
126 FileDialogHelper( sal_Int16 nDialogType
,
128 const OUString
& aFilterUIName
,
129 const OUString
& aExtName
,
130 const OUString
& rStandardDir
,
131 const ::com::sun::star::uno::Sequence
< OUString
>& rBlackList
,
132 Window
* _pPreferredParent
= NULL
);
135 virtual ~FileDialogHelper();
138 void StartExecuteModal( const Link
& rEndDialogHdl
);
139 inline ErrCode
GetError() const { return m_nError
; }
140 sal_Int16
GetDialogType() const;
141 sal_Bool
IsPasswordEnabled() const;
142 OUString
GetRealFilter() const;
144 void SetTitle( const OUString
& rNewTitle
);
145 OUString
GetPath() const;
147 /** @deprected: Don't use this method to retrieve the selected files
148 There are file picker which can provide multiple selected file which belong
149 to different folders. As this method always provides the root folder for all selected
150 files this cannot work.
152 ::com::sun::star::uno::Sequence
< OUString
> GetMPath() const;
154 /** Provides the selected files with full path information */
155 ::com::sun::star::uno::Sequence
< OUString
> GetSelectedFiles() const;
157 void AddFilter( const OUString
& rFilterName
, const OUString
& rExtension
);
158 void SetCurrentFilter( const OUString
& rFilter
);
160 /** sets an initial display directory/file name
163 don't use this method. It contains a lot of magic in determining whether the
164 last segment of the given path/URL denotes a file name or a folder, and by
165 definition, it cannot succeed with this magic *all* the time - there will
166 always be scenarios where it fails.
168 Use SetDisplayFolder and SetFileName.
170 void SetDisplayDirectory( const OUString
& rPath
);
172 /** sets a new folder whose content is to be displayed in the file picker
175 specifies the URL of the folder whose content is to be displayed.<br/>
176 If the URL doesn't denote a valid (existent and accessible) folder, the
177 request is silently dropped.
178 @throws ::com::sun::star::uno::RuntimeException
179 if the invocation of any of the file picker or UCB methods throws a RuntimeException.
181 void SetDisplayFolder( const OUString
& _rURL
);
183 /** sets an initial file name to display
185 This method is usually used in "save-as" contexts, where the application should
186 suggest an initial name for the file to save.
188 Calling this method is nearly equivalent to calling <code>GetFilePicker().setDefaultName( _rFileName )</code>,
189 with the following differences:
190 <ul><li>The FileDialogHelper remembers the given file name, and upon execution,
191 strips its extension if the dialog is set up for "automatic file name extension".</li>
192 <li>Exceptions thrown from the <code>XFilePicker</code> are caught and silenced.</li>
195 void SetFileName( const OUString
& _rFileName
);
197 OUString
GetCurrentFilter() const;
198 OUString
GetDisplayDirectory() const;
199 ErrCode
GetGraphic( Graphic
& rGraphic
) const;
201 ::com::sun::star::uno::Reference
< ::com::sun::star::ui::dialogs::XFilePicker
> GetFilePicker() const;
203 // XFilePickerListener methods
204 virtual void SAL_CALL
FileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent
& aEvent
);
205 virtual void SAL_CALL
DirectoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent
& aEvent
);
206 virtual void SAL_CALL
ControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent
& aEvent
);
207 virtual void SAL_CALL
DialogSizeChanged();
208 virtual OUString SAL_CALL
HelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent
& aEvent
);
210 // XDialogClosedListener methods
211 virtual void SAL_CALL
DialogClosed( const ::com::sun::star::ui::dialogs::DialogClosedEvent
& _rEvent
);
213 /** sets help ids for the controls in the dialog
215 Pointer to a 0-terminated array of control ids. They must be recruited from the
216 CommonFilePickerElementIds and ExtendedFilePickerElementIds values.
218 Pointer to an array of help ids. For each element in _pControlId, there must be
219 a corresponding element herein.
221 void SetControlHelpIds( const sal_Int16
* _pControlId
, const char** _pHelpId
);
222 void CreateMatcher( const OUString
& rName
);
224 /** sets the context of the dialog and trigger necessary actions e.g. loading config, setting help id
226 New context for the dialog.
228 void SetContext( Context _eNewContext
);
230 DECL_LINK( ExecuteSystemFilePicker
, void* );
232 ErrCode
Execute( std::vector
<OUString
>& rpURLList
,
235 const OUString
& rDirPath
);
236 ErrCode
Execute( SfxItemSet
*& rpSet
,
240 #define SFX2_IMPL_DIALOG_CONFIG 0
241 #define SFX2_IMPL_DIALOG_SYSTEM 1
242 #define SFX2_IMPL_DIALOG_OOO 2
244 ErrCode
FileOpenDialog_Impl( sal_Int16 nDialogType
,
246 const OUString
& rFact
,
247 std::vector
<OUString
>& rpURLList
,
250 const OUString
* pPath
= NULL
,
251 sal_Int16 nDialog
= SFX2_IMPL_DIALOG_CONFIG
,
252 const OUString
& rStandardDir
= OUString(),
253 const ::com::sun::star::uno::Sequence
< OUString
>& rBlackList
= ::com::sun::star::uno::Sequence
< OUString
>());
256 ErrCode
RequestPassword(const SfxFilter
* pCurrentFilter
, OUString
& aURL
, SfxItemSet
* pSet
);
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */