1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX
29 #define FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
36 #pragma warning( disable : 4917 )
39 #include "platform_vista.h"
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>
58 #pragma warning(push, 1)
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
70 #error "Clash on using CSS as namespace define."
72 #define css ::com::sun::star
79 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
83 static const ::sal_Int32 FEATURE_AUTOEXTENSION
= 1;
84 static const ::sal_Int32 FEATURE_PASSWORD
= 2;
85 static const ::sal_Int32 FEATURE_FILTEROPTIONS
= 4;
86 static const ::sal_Int32 FEATURE_SELECTION
= 8;
87 static const ::sal_Int32 FEATURE_TEMPLATE
= 16;
88 static const ::sal_Int32 FEATURE_LINK
= 32;
89 static const ::sal_Int32 FEATURE_PREVIEW
= 64;
90 static const ::sal_Int32 FEATURE_IMAGETEMPLATE
= 128;
91 static const ::sal_Int32 FEATURE_PLAY
= 256;
92 static const ::sal_Int32 FEATURE_READONLY
= 512;
93 static const ::sal_Int32 FEATURE_VERSION
= 1024;
95 static const ::rtl::OUString PROP_PICKER_LISTENER
= ::rtl::OUString::createFromAscii("picker_listener" ); // [XFilePickerListenert]
96 static const ::rtl::OUString PROP_DIALOG_SHOW_RESULT
= ::rtl::OUString::createFromAscii("dialog_show_result" ); // [sal_Bool] true=OK, false=CANCEL
97 static const ::rtl::OUString PROP_SELECTED_FILES
= ::rtl::OUString::createFromAscii("selected_files" ); // [seq< OUString >] contains all user selected files (can be empty!)
98 static const ::rtl::OUString PROP_MULTISELECTION_MODE
= ::rtl::OUString::createFromAscii("multiselection_mode"); // [sal_Bool] true=ON, false=OFF
99 static const ::rtl::OUString PROP_TITLE
= ::rtl::OUString::createFromAscii("title" ); // [OUString]
100 static const ::rtl::OUString PROP_FILENAME
= ::rtl::OUString::createFromAscii("filename" ); // [OUString]
101 static const ::rtl::OUString PROP_DIRECTORY
= ::rtl::OUString::createFromAscii("directory" ); // [OUString]
102 static const ::rtl::OUString PROP_FEATURES
= ::rtl::OUString::createFromAscii("features" ); // [sal_Int32]
103 static const ::rtl::OUString PROP_TEMPLATE_DESCR
= ::rtl::OUString::createFromAscii("templatedescription"); // [sal_Int32]
104 static const ::rtl::OUString PROP_FILTER_TITLE
= ::rtl::OUString::createFromAscii("filter_title" ); // [OUString]
105 static const ::rtl::OUString PROP_FILTER_VALUE
= ::rtl::OUString::createFromAscii("filter_value" ); // [OUString]
106 static const ::rtl::OUString PROP_FORCE
= ::rtl::OUString::createFromAscii("force" ); // [sal_Bool]
108 static const ::rtl::OUString PROP_CONTROL_ID
= ::rtl::OUString::createFromAscii("control_id" ); // [sal_Int16]
109 static const ::rtl::OUString PROP_CONTROL_ACTION
= ::rtl::OUString::createFromAscii("control_action" ); // [sal_Int16]
110 static const ::rtl::OUString PROP_CONTROL_VALUE
= ::rtl::OUString::createFromAscii("control_value" ); // [Any]
111 static const ::rtl::OUString PROP_CONTROL_LABEL
= ::rtl::OUString::createFromAscii("control_label" ); // [OUString]
112 static const ::rtl::OUString PROP_CONTROL_ENABLE
= ::rtl::OUString::createFromAscii("control_enable" ); // [sal_Bool] true=ON, false=OFF
114 //-----------------------------------------------------------------------------
115 /** native implementation of the file picker on Vista and upcoming windows versions.
116 * This dialog uses COM internaly. Further it marshall every request so it will
117 * be executed within it's own STA thread !
119 //-----------------------------------------------------------------------------
120 class VistaFilePickerImpl
: private ::cppu::BaseMutex
121 , public RequestHandler
122 , public IVistaFilePickerInternalNotify
126 //---------------------------------------------------------------------
127 /** used for marshalling requests.
128 * Will be used to map requests to the right implementations.
133 E_ADD_PICKER_LISTENER
,
134 E_REMOVE_PICKER_LISTENER
,
136 E_SET_CURRENT_FILTER
,
137 E_GET_CURRENT_FILTER
,
138 E_CREATE_OPEN_DIALOG
,
139 E_CREATE_SAVE_DIALOG
,
140 E_SET_MULTISELECTION_MODE
,
146 E_GET_SELECTED_FILES
,
157 //---------------------------------------------------------------------
158 // ctor/dtor - nothing special
159 //---------------------------------------------------------------------
160 VistaFilePickerImpl();
161 virtual ~VistaFilePickerImpl();
163 //---------------------------------------------------------------------
165 //---------------------------------------------------------------------
167 virtual void before();
168 virtual void doRequest(const RequestRef
& rRequest
);
169 virtual void after();
171 //---------------------------------------------------------------------
172 virtual void onAutoExtensionChanged (bool bChecked
);
176 //---------------------------------------------------------------------
177 /// implementation of request E_ADD_FILEPICKER_LISTENER
178 void impl_sta_addFilePickerListener(const RequestRef
& rRequest
);
180 //---------------------------------------------------------------------
181 /// implementation of request E_REMOVE_FILEPICKER_LISTENER
182 void impl_sta_removeFilePickerListener(const RequestRef
& rRequest
);
184 //---------------------------------------------------------------------
185 /// implementation of request E_APPEND_FILTER
186 void impl_sta_appendFilter(const RequestRef
& rRequest
);
188 //---------------------------------------------------------------------
189 /// implementation of request E_SET_CURRENT_FILTER
190 void impl_sta_setCurrentFilter(const RequestRef
& rRequest
);
192 //---------------------------------------------------------------------
193 /// implementation of request E_GET_CURRENT_FILTER
194 void impl_sta_getCurrentFilter(const RequestRef
& rRequest
);
196 //---------------------------------------------------------------------
197 /// implementation of request E_CREATE_OPEN_DIALOG
198 void impl_sta_CreateOpenDialog(const RequestRef
& rRequest
);
200 //---------------------------------------------------------------------
201 /// implementation of request E_CREATE_SAVE_DIALOG
202 void impl_sta_CreateSaveDialog(const RequestRef
& rRequest
);
204 //---------------------------------------------------------------------
205 /// implementation of request E_SET_MULTISELECTION_MODE
206 void impl_sta_SetMultiSelectionMode(const RequestRef
& rRequest
);
208 //---------------------------------------------------------------------
209 /// implementation of request E_SET_TITLE
210 void impl_sta_SetTitle(const RequestRef
& rRequest
);
212 //---------------------------------------------------------------------
213 /// implementation of request E_SET_FILENAME
214 void impl_sta_SetFileName(const RequestRef
& rRequest
);
216 //---------------------------------------------------------------------
217 /// implementation of request E_SET_DIRECTORY
218 void impl_sta_SetDirectory(const RequestRef
& rRequest
);
220 //---------------------------------------------------------------------
221 /// implementation of request E_GET_DIRECTORY
222 void impl_sta_GetDirectory(const RequestRef
& rRequest
);
224 //---------------------------------------------------------------------
225 /// implementation of request E_SET_DEFAULT_NAME
226 void impl_sta_SetDefaultName(const RequestRef
& rRequest
);
228 //---------------------------------------------------------------------
229 /// implementation of request E_GET_SELECTED_FILES
230 void impl_sta_getSelectedFiles(const RequestRef
& rRequest
);
232 //---------------------------------------------------------------------
233 /// implementation of request E_SHOW_DIALOG_MODAL
234 void impl_sta_ShowDialogModal(const RequestRef
& rRequest
);
236 //---------------------------------------------------------------------
237 /// implementation of request E_SET_CONTROL_VALUE
238 void impl_sta_SetControlValue(const RequestRef
& rRequest
);
240 //---------------------------------------------------------------------
241 /// implementation of request E_GET_CONTROL_VALUE
242 void impl_sta_GetControlValue(const RequestRef
& rRequest
);
244 //---------------------------------------------------------------------
245 /// implementation of request E_SET_CONTROL_LABEL
246 void impl_sta_SetControlLabel(const RequestRef
& rRequest
);
248 //---------------------------------------------------------------------
249 /// implementation of request E_GET_CONTROL_LABEL
250 void impl_sta_GetControlLabel(const RequestRef
& rRequest
);
252 //---------------------------------------------------------------------
253 /// implementation of request E_ENABLE_CONTROL
254 void impl_sta_EnableControl(const RequestRef
& rRequest
);
256 //---------------------------------------------------------------------
257 /** create all needed (optional!) UI controls adressed by the field nFeatures.
258 * The given number nFeatures is used as a flag field. Use const values FEATURE_XXX
261 * Internal new controls will be added to the dialog. Every control can be accessed
262 * by it's own control id. Those control ID must be one of the const set
263 * css::ui::dialogs::ExtendedFilePickerElementIds.
265 * @see setControlValue()
266 * @see getControlValue()
267 * @see setControlLabel()
268 * @see getControlLabel()
269 * @see enableControl()
272 * flag field(!) knows all features wich must be enabled.
274 void impl_sta_enableFeatures(::sal_Int32 nFeatures
, ::sal_Int32 nTemplate
);
276 //---------------------------------------------------------------------
277 /** returns an interface, which can be used to customize the internaly used
280 * Because we use two member (open/save dialog) internaly, this method
281 * ask the current active one for it's customization interface.
283 * @return the customization interface for the current used dialog.
286 TFileDialogCustomize
impl_getCustomizeInterface();
287 TFileDialog
impl_getBaseDialogInterface();
289 //---------------------------------------------------------------------
290 /// fill filter list of internal used dialog.
291 void impl_sta_setFiltersOnDialog();
293 void impl_SetDefaultExtension( const rtl::OUString
& currentFilter
);
297 //---------------------------------------------------------------------
298 /// COM object representing a file open dialog
299 TFileOpenDialog m_iDialogOpen
;
301 //---------------------------------------------------------------------
302 /// COM object representing a file save dialog
303 TFileSaveDialog m_iDialogSave
;
305 //---------------------------------------------------------------------
306 /// knows the return state of the last COM call
307 HRESULT m_hLastResult
;
309 //---------------------------------------------------------------------
310 /// @todo document me
311 CFilterContainer m_lFilters
;
313 //---------------------------------------------------------------------
314 /** cache last selected list of files
315 * Because those list must be retrieved directly after closing the dialog
316 * (and only in case it was finished successfully) we cache it internaly.
317 * Because the outside provided UNO API decouple showing the dialog
318 * and asking for results .-)
320 css::uno::Sequence
< ::rtl::OUString
> m_lLastFiles
;
322 //---------------------------------------------------------------------
323 /** help us to handle dialog events and provide them to interested office
326 TFileDialogEvents m_iEventHandler
;
328 //---------------------------------------------------------------------
329 /// @todo document me
330 ::sal_Bool m_bInExecute
;
332 ::sal_Bool m_bWasExecuted
;
334 // handle to parent window
335 HWND m_hParentWindow
;
338 ::rtl::OUString m_sDirectory
;
341 ::rtl::OUString m_sFilename
;
344 CResourceProvider m_ResProvider
;
349 } // namespace fpicker
353 #endif // FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX