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 .
20 #ifndef FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX
21 #define FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX
24 #pragma warning( disable : 4917 )
27 #include "platform_vista.h"
30 #pragma warning(push, 1)
37 // Without IFileDialogCustomize we can't do this
38 #ifdef __IFileDialogCustomize_INTERFACE_DEFINED__
40 #include "asyncrequests.hxx"
42 #include "vistatypes.h"
43 #include "FilterContainer.hxx"
44 #include "VistaFilePickerEventHandler.hxx"
45 #include "IVistaFilePickerInternalNotify.hxx"
46 #include "../misc/resourceprovider.hxx"
48 #include <com/sun/star/uno/Sequence.hxx>
50 #include <comphelper/sequenceashashmap.hxx>
51 #include <cppuhelper/interfacecontainer.h>
52 #include <cppuhelper/basemutex.hxx>
53 #include <osl/thread.hxx>
54 #include <osl/conditn.hxx>
55 #include <rtl/ustring.hxx>
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 static const ::sal_Int32 FEATURE_AUTOEXTENSION
= 1;
66 static const ::sal_Int32 FEATURE_PASSWORD
= 2;
67 static const ::sal_Int32 FEATURE_FILTEROPTIONS
= 4;
68 static const ::sal_Int32 FEATURE_SELECTION
= 8;
69 static const ::sal_Int32 FEATURE_TEMPLATE
= 16;
70 static const ::sal_Int32 FEATURE_LINK
= 32;
71 static const ::sal_Int32 FEATURE_PREVIEW
= 64;
72 static const ::sal_Int32 FEATURE_IMAGETEMPLATE
= 128;
73 static const ::sal_Int32 FEATURE_PLAY
= 256;
74 static const ::sal_Int32 FEATURE_READONLY
= 512;
75 static const ::sal_Int32 FEATURE_VERSION
= 1024;
77 static const OUString
PROP_PICKER_LISTENER("picker_listener" ); // [XFilePickerListenert]
78 static const OUString
PROP_DIALOG_SHOW_RESULT("dialog_show_result" ); // [sal_Bool] true=OK, false=CANCEL
79 static const OUString
PROP_SELECTED_FILES("selected_files" ); // [seq< OUString >] contains all user selected files (can be empty!)
80 static const OUString
PROP_MULTISELECTION_MODE("multiselection_mode"); // [sal_Bool] true=ON, false=OFF
81 static const OUString
PROP_TITLE("title" ); // [OUString]
82 static const OUString
PROP_FILENAME("filename" ); // [OUString]
83 static const OUString
PROP_DIRECTORY("directory" ); // [OUString]
84 static const OUString
PROP_FEATURES("features" ); // [sal_Int32]
85 static const OUString
PROP_TEMPLATE_DESCR("templatedescription"); // [sal_Int32]
86 static const OUString
PROP_FILTER_TITLE("filter_title" ); // [OUString]
87 static const OUString
PROP_FILTER_VALUE("filter_value" ); // [OUString]
88 static const OUString
PROP_FORCE("force" ); // [sal_Bool]
89 static const OUString
PROP_FILTER_GROUP("filter-group" ); // [seq< css:beans::StringPair >] contains a group of filters
91 static const OUString
PROP_CONTROL_ID("control_id" ); // [sal_Int16]
92 static const OUString
PROP_CONTROL_ACTION("control_action" ); // [sal_Int16]
93 static const OUString
PROP_CONTROL_VALUE("control_value" ); // [Any]
94 static const OUString
PROP_CONTROL_LABEL("control_label" ); // [OUString]
95 static const OUString
PROP_CONTROL_ENABLE("control_enable" ); // [sal_Bool] true=ON, false=OFF
96 static const OUString
STRING_SEPARATOR("------------------------------------------" );
98 //-----------------------------------------------------------------------------
99 /** native implementation of the file picker on Vista and upcoming windows versions.
100 * This dialog uses COM internaly. Further it marshall every request so it will
101 * be executed within it's own STA thread !
103 //-----------------------------------------------------------------------------
104 class VistaFilePickerImpl
: private ::cppu::BaseMutex
105 , public RequestHandler
106 , public IVistaFilePickerInternalNotify
110 //---------------------------------------------------------------------
111 /** used for marshalling requests.
112 * Will be used to map requests to the right implementations.
117 E_ADD_PICKER_LISTENER
,
118 E_REMOVE_PICKER_LISTENER
,
120 E_SET_CURRENT_FILTER
,
121 E_GET_CURRENT_FILTER
,
122 E_CREATE_OPEN_DIALOG
,
123 E_CREATE_SAVE_DIALOG
,
124 E_SET_MULTISELECTION_MODE
,
130 E_GET_SELECTED_FILES
,
142 //---------------------------------------------------------------------
143 // ctor/dtor - nothing special
144 //---------------------------------------------------------------------
145 VistaFilePickerImpl();
146 virtual ~VistaFilePickerImpl();
148 //---------------------------------------------------------------------
150 //---------------------------------------------------------------------
152 virtual void before();
153 virtual void doRequest(const RequestRef
& rRequest
);
154 virtual void after();
156 //---------------------------------------------------------------------
157 // IVistaFilePickerInternalNotify
158 //---------------------------------------------------------------------
159 virtual void onAutoExtensionChanged (bool bChecked
);
160 virtual bool onFileTypeChanged( UINT nTypeIndex
);
164 //---------------------------------------------------------------------
165 /// implementation of request E_ADD_FILEPICKER_LISTENER
166 void impl_sta_addFilePickerListener(const RequestRef
& rRequest
);
168 //---------------------------------------------------------------------
169 /// implementation of request E_REMOVE_FILEPICKER_LISTENER
170 void impl_sta_removeFilePickerListener(const RequestRef
& rRequest
);
172 //---------------------------------------------------------------------
173 /// implementation of request E_APPEND_FILTER
174 void impl_sta_appendFilter(const RequestRef
& rRequest
);
176 //---------------------------------------------------------------------
177 /// implementation of request E_APPEND_FILTERGROUP
178 void impl_sta_appendFilterGroup(const RequestRef
& rRequest
);
180 //---------------------------------------------------------------------
181 /// implementation of request E_SET_CURRENT_FILTER
182 void impl_sta_setCurrentFilter(const RequestRef
& rRequest
);
184 //---------------------------------------------------------------------
185 /// implementation of request E_GET_CURRENT_FILTER
186 void impl_sta_getCurrentFilter(const RequestRef
& rRequest
);
188 //---------------------------------------------------------------------
189 /// implementation of request E_CREATE_OPEN_DIALOG
190 void impl_sta_CreateOpenDialog(const RequestRef
& rRequest
);
192 //---------------------------------------------------------------------
193 /// implementation of request E_CREATE_SAVE_DIALOG
194 void impl_sta_CreateSaveDialog(const RequestRef
& rRequest
);
196 //---------------------------------------------------------------------
197 /// implementation of request E_SET_MULTISELECTION_MODE
198 void impl_sta_SetMultiSelectionMode(const RequestRef
& rRequest
);
200 //---------------------------------------------------------------------
201 /// implementation of request E_SET_TITLE
202 void impl_sta_SetTitle(const RequestRef
& rRequest
);
204 //---------------------------------------------------------------------
205 /// implementation of request E_SET_FILENAME
206 void impl_sta_SetFileName(const RequestRef
& rRequest
);
208 //---------------------------------------------------------------------
209 /// implementation of request E_SET_DIRECTORY
210 void impl_sta_SetDirectory(const RequestRef
& rRequest
);
212 //---------------------------------------------------------------------
213 /// implementation of request E_GET_DIRECTORY
214 void impl_sta_GetDirectory(const RequestRef
& rRequest
);
216 //---------------------------------------------------------------------
217 /// implementation of request E_SET_DEFAULT_NAME
218 void impl_sta_SetDefaultName(const RequestRef
& rRequest
);
220 //---------------------------------------------------------------------
221 /// implementation of request E_GET_SELECTED_FILES
222 void impl_sta_getSelectedFiles(const RequestRef
& rRequest
);
224 //---------------------------------------------------------------------
225 /// implementation of request E_SHOW_DIALOG_MODAL
226 void impl_sta_ShowDialogModal(const RequestRef
& rRequest
);
228 //---------------------------------------------------------------------
229 /// implementation of request E_SET_CONTROL_VALUE
230 void impl_sta_SetControlValue(const RequestRef
& rRequest
);
232 //---------------------------------------------------------------------
233 /// implementation of request E_GET_CONTROL_VALUE
234 void impl_sta_GetControlValue(const RequestRef
& rRequest
);
236 //---------------------------------------------------------------------
237 /// implementation of request E_SET_CONTROL_LABEL
238 void impl_sta_SetControlLabel(const RequestRef
& rRequest
);
240 //---------------------------------------------------------------------
241 /// implementation of request E_GET_CONTROL_LABEL
242 void impl_sta_GetControlLabel(const RequestRef
& rRequest
);
244 //---------------------------------------------------------------------
245 /// implementation of request E_ENABLE_CONTROL
246 void impl_sta_EnableControl(const RequestRef
& rRequest
);
248 //---------------------------------------------------------------------
249 /** create all needed (optional!) UI controls addressed by the field nFeatures.
250 * The given number nFeatures is used as a flag field. Use const values FEATURE_XXX
253 * Internal new controls will be added to the dialog. Every control can be accessed
254 * by it's own control id. Those control ID must be one of the const set
255 * css::ui::dialogs::ExtendedFilePickerElementIds.
257 * @see setControlValue()
258 * @see getControlValue()
259 * @see setControlLabel()
260 * @see getControlLabel()
261 * @see enableControl()
264 * flag field(!) knows all features which must be enabled.
266 void impl_sta_enableFeatures(::sal_Int32 nFeatures
, ::sal_Int32 nTemplate
);
268 //---------------------------------------------------------------------
269 /** returns an interface, which can be used to customize the internaly used
272 * Because we use two member (open/save dialog) internaly, this method
273 * ask the current active one for it's customization interface.
275 * @return the customization interface for the current used dialog.
278 TFileDialogCustomize
impl_getCustomizeInterface();
279 TFileDialog
impl_getBaseDialogInterface();
281 //---------------------------------------------------------------------
282 /// fill filter list of internal used dialog.
283 void impl_sta_setFiltersOnDialog();
285 void impl_SetDefaultExtension( const OUString
& currentFilter
);
289 //---------------------------------------------------------------------
290 /// COM object representing a file open dialog
291 TFileOpenDialog m_iDialogOpen
;
293 //---------------------------------------------------------------------
294 /// COM object representing a file save dialog
295 TFileSaveDialog m_iDialogSave
;
297 //---------------------------------------------------------------------
298 /// knows the return state of the last COM call
299 HRESULT m_hLastResult
;
301 //---------------------------------------------------------------------
302 /// @todo document me
303 CFilterContainer m_lFilters
;
305 //---------------------------------------------------------------------
306 /** cache last selected list of files
307 * Because those list must be retrieved directly after closing the dialog
308 * (and only in case it was finished successfully) we cache it internaly.
309 * Because the outside provided UNO API decouple showing the dialog
310 * and asking for results .-)
312 css::uno::Sequence
< OUString
> m_lLastFiles
;
314 //---------------------------------------------------------------------
315 /** help us to handle dialog events and provide them to interested office
318 TFileDialogEvents m_iEventHandler
;
320 //---------------------------------------------------------------------
321 /// @todo document me
322 ::sal_Bool m_bInExecute
;
324 ::sal_Bool m_bWasExecuted
;
326 // handle to parent window
327 HWND m_hParentWindow
;
330 OUString m_sDirectory
;
333 OUString m_sFilename
;
336 CResourceProvider m_ResProvider
;
341 } // namespace fpicker
343 #endif // __IFileDialogCustomize_INTERFACE_DEFINED__
345 #endif // FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */