1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VistaFilePickerImpl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX
32 #define FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
39 #pragma warning( disable : 4917 )
42 #include "platform_vista.h"
43 #include "asyncrequests.hxx"
45 #include "vistatypes.h"
46 #include "FilterContainer.hxx"
47 #include "VistaFilePickerEventHandler.hxx"
48 #include "IVistaFilePickerInternalNotify.hxx"
49 #include "..\misc\resourceprovider.hxx"
51 #include <com/sun/star/uno/Sequence.hxx>
53 #include <comphelper/sequenceashashmap.hxx>
54 #include <cppuhelper/interfacecontainer.h>
55 #include <cppuhelper/basemutex.hxx>
56 #include <osl/thread.hxx>
57 #include <osl/conditn.hxx>
58 #include <rtl/ustring.hxx>
61 #pragma warning(push, 1)
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
73 #error "Clash on using CSS as namespace define."
75 #define css ::com::sun::star
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 static const ::sal_Int32 FEATURE_AUTOEXTENSION
= 1;
87 static const ::sal_Int32 FEATURE_PASSWORD
= 2;
88 static const ::sal_Int32 FEATURE_FILTEROPTIONS
= 4;
89 static const ::sal_Int32 FEATURE_SELECTION
= 8;
90 static const ::sal_Int32 FEATURE_TEMPLATE
= 16;
91 static const ::sal_Int32 FEATURE_LINK
= 32;
92 static const ::sal_Int32 FEATURE_PREVIEW
= 64;
93 static const ::sal_Int32 FEATURE_IMAGETEMPLATE
= 128;
94 static const ::sal_Int32 FEATURE_PLAY
= 256;
95 static const ::sal_Int32 FEATURE_READONLY
= 512;
96 static const ::sal_Int32 FEATURE_VERSION
= 1024;
98 static const ::rtl::OUString PROP_PICKER_LISTENER
= ::rtl::OUString::createFromAscii("picker_listener" ); // [XFilePickerListenert]
99 static const ::rtl::OUString PROP_DIALOG_SHOW_RESULT
= ::rtl::OUString::createFromAscii("dialog_show_result" ); // [sal_Bool] true=OK, false=CANCEL
100 static const ::rtl::OUString PROP_SELECTED_FILES
= ::rtl::OUString::createFromAscii("selected_files" ); // [seq< OUString >] contains all user selected files (can be empty!)
101 static const ::rtl::OUString PROP_MULTISELECTION_MODE
= ::rtl::OUString::createFromAscii("multiselection_mode"); // [sal_Bool] true=ON, false=OFF
102 static const ::rtl::OUString PROP_TITLE
= ::rtl::OUString::createFromAscii("title" ); // [OUString]
103 static const ::rtl::OUString PROP_FILENAME
= ::rtl::OUString::createFromAscii("filename" ); // [OUString]
104 static const ::rtl::OUString PROP_DIRECTORY
= ::rtl::OUString::createFromAscii("directory" ); // [OUString]
105 static const ::rtl::OUString PROP_FEATURES
= ::rtl::OUString::createFromAscii("features" ); // [sal_Int32]
106 static const ::rtl::OUString PROP_TEMPLATE_DESCR
= ::rtl::OUString::createFromAscii("templatedescription"); // [sal_Int32]
107 static const ::rtl::OUString PROP_FILTER_TITLE
= ::rtl::OUString::createFromAscii("filter_title" ); // [OUString]
108 static const ::rtl::OUString PROP_FILTER_VALUE
= ::rtl::OUString::createFromAscii("filter_value" ); // [OUString]
109 static const ::rtl::OUString PROP_FORCE
= ::rtl::OUString::createFromAscii("force" ); // [sal_Bool]
111 static const ::rtl::OUString PROP_CONTROL_ID
= ::rtl::OUString::createFromAscii("control_id" ); // [sal_Int16]
112 static const ::rtl::OUString PROP_CONTROL_ACTION
= ::rtl::OUString::createFromAscii("control_action" ); // [sal_Int16]
113 static const ::rtl::OUString PROP_CONTROL_VALUE
= ::rtl::OUString::createFromAscii("control_value" ); // [Any]
114 static const ::rtl::OUString PROP_CONTROL_LABEL
= ::rtl::OUString::createFromAscii("control_label" ); // [OUString]
115 static const ::rtl::OUString PROP_CONTROL_ENABLE
= ::rtl::OUString::createFromAscii("control_enable" ); // [sal_Bool] true=ON, false=OFF
117 //-----------------------------------------------------------------------------
118 /** native implementation of the file picker on Vista and upcoming windows versions.
119 * This dialog uses COM internaly. Further it marshall every request so it will
120 * be executed within it's own STA thread !
122 //-----------------------------------------------------------------------------
123 class VistaFilePickerImpl
: private ::cppu::BaseMutex
124 , public RequestHandler
125 , public IVistaFilePickerInternalNotify
129 //---------------------------------------------------------------------
130 /** used for marshalling requests.
131 * Will be used to map requests to the right implementations.
136 E_ADD_PICKER_LISTENER
,
137 E_REMOVE_PICKER_LISTENER
,
139 E_SET_CURRENT_FILTER
,
140 E_GET_CURRENT_FILTER
,
141 E_CREATE_OPEN_DIALOG
,
142 E_CREATE_SAVE_DIALOG
,
143 E_SET_MULTISELECTION_MODE
,
149 E_GET_SELECTED_FILES
,
160 //---------------------------------------------------------------------
161 // ctor/dtor - nothing special
162 //---------------------------------------------------------------------
163 VistaFilePickerImpl();
164 virtual ~VistaFilePickerImpl();
166 //---------------------------------------------------------------------
168 //---------------------------------------------------------------------
170 virtual void before();
171 virtual void doRequest(const RequestRef
& rRequest
);
172 virtual void after();
174 //---------------------------------------------------------------------
175 virtual void onAutoExtensionChanged (bool bChecked
);
179 //---------------------------------------------------------------------
180 /// implementation of request E_ADD_FILEPICKER_LISTENER
181 void impl_sta_addFilePickerListener(const RequestRef
& rRequest
);
183 //---------------------------------------------------------------------
184 /// implementation of request E_REMOVE_FILEPICKER_LISTENER
185 void impl_sta_removeFilePickerListener(const RequestRef
& rRequest
);
187 //---------------------------------------------------------------------
188 /// implementation of request E_APPEND_FILTER
189 void impl_sta_appendFilter(const RequestRef
& rRequest
);
191 //---------------------------------------------------------------------
192 /// implementation of request E_SET_CURRENT_FILTER
193 void impl_sta_setCurrentFilter(const RequestRef
& rRequest
);
195 //---------------------------------------------------------------------
196 /// implementation of request E_GET_CURRENT_FILTER
197 void impl_sta_getCurrentFilter(const RequestRef
& rRequest
);
199 //---------------------------------------------------------------------
200 /// implementation of request E_CREATE_OPEN_DIALOG
201 void impl_sta_CreateOpenDialog(const RequestRef
& rRequest
);
203 //---------------------------------------------------------------------
204 /// implementation of request E_CREATE_SAVE_DIALOG
205 void impl_sta_CreateSaveDialog(const RequestRef
& rRequest
);
207 //---------------------------------------------------------------------
208 /// implementation of request E_SET_MULTISELECTION_MODE
209 void impl_sta_SetMultiSelectionMode(const RequestRef
& rRequest
);
211 //---------------------------------------------------------------------
212 /// implementation of request E_SET_TITLE
213 void impl_sta_SetTitle(const RequestRef
& rRequest
);
215 //---------------------------------------------------------------------
216 /// implementation of request E_SET_FILENAME
217 void impl_sta_SetFileName(const RequestRef
& rRequest
);
219 //---------------------------------------------------------------------
220 /// implementation of request E_SET_DIRECTORY
221 void impl_sta_SetDirectory(const RequestRef
& rRequest
);
223 //---------------------------------------------------------------------
224 /// implementation of request E_GET_DIRECTORY
225 void impl_sta_GetDirectory(const RequestRef
& rRequest
);
227 //---------------------------------------------------------------------
228 /// implementation of request E_SET_DEFAULT_NAME
229 void impl_sta_SetDefaultName(const RequestRef
& rRequest
);
231 //---------------------------------------------------------------------
232 /// implementation of request E_GET_SELECTED_FILES
233 void impl_sta_getSelectedFiles(const RequestRef
& rRequest
);
235 //---------------------------------------------------------------------
236 /// implementation of request E_SHOW_DIALOG_MODAL
237 void impl_sta_ShowDialogModal(const RequestRef
& rRequest
);
239 //---------------------------------------------------------------------
240 /// implementation of request E_SET_CONTROL_VALUE
241 void impl_sta_SetControlValue(const RequestRef
& rRequest
);
243 //---------------------------------------------------------------------
244 /// implementation of request E_GET_CONTROL_VALUE
245 void impl_sta_GetControlValue(const RequestRef
& rRequest
);
247 //---------------------------------------------------------------------
248 /// implementation of request E_SET_CONTROL_LABEL
249 void impl_sta_SetControlLabel(const RequestRef
& rRequest
);
251 //---------------------------------------------------------------------
252 /// implementation of request E_GET_CONTROL_LABEL
253 void impl_sta_GetControlLabel(const RequestRef
& rRequest
);
255 //---------------------------------------------------------------------
256 /// implementation of request E_ENABLE_CONTROL
257 void impl_sta_EnableControl(const RequestRef
& rRequest
);
259 //---------------------------------------------------------------------
260 /** create all needed (optional!) UI controls adressed by the field nFeatures.
261 * The given number nFeatures is used as a flag field. Use const values FEATURE_XXX
264 * Internal new controls will be added to the dialog. Every control can be accessed
265 * by it's own control id. Those control ID must be one of the const set
266 * css::ui::dialogs::ExtendedFilePickerElementIds.
268 * @see setControlValue()
269 * @see getControlValue()
270 * @see setControlLabel()
271 * @see getControlLabel()
272 * @see enableControl()
275 * flag field(!) knows all features wich must be enabled.
277 void impl_sta_enableFeatures(::sal_Int32 nFeatures
, ::sal_Int32 nTemplate
);
279 //---------------------------------------------------------------------
280 /** returns an interface, which can be used to customize the internaly used
283 * Because we use two member (open/save dialog) internaly, this method
284 * ask the current active one for it's customization interface.
286 * @return the customization interface for the current used dialog.
289 TFileDialogCustomize
impl_getCustomizeInterface();
290 TFileDialog
impl_getBaseDialogInterface();
292 //---------------------------------------------------------------------
293 /// fill filter list of internal used dialog.
294 void impl_sta_setFiltersOnDialog();
296 void impl_SetDefaultExtension( const rtl::OUString
& currentFilter
);
300 //---------------------------------------------------------------------
301 /// COM object representing a file open dialog
302 TFileOpenDialog m_iDialogOpen
;
304 //---------------------------------------------------------------------
305 /// COM object representing a file save dialog
306 TFileSaveDialog m_iDialogSave
;
308 //---------------------------------------------------------------------
309 /// knows the return state of the last COM call
310 HRESULT m_hLastResult
;
312 //---------------------------------------------------------------------
313 /// @todo document me
314 CFilterContainer m_lFilters
;
316 //---------------------------------------------------------------------
317 /** cache last selected list of files
318 * Because those list must be retrieved directly after closing the dialog
319 * (and only in case it was finished successfully) we cache it internaly.
320 * Because the outside provided UNO API decouple showing the dialog
321 * and asking for results .-)
323 css::uno::Sequence
< ::rtl::OUString
> m_lLastFiles
;
325 //---------------------------------------------------------------------
326 /** help us to handle dialog events and provide them to interested office
329 TFileDialogEvents m_iEventHandler
;
331 //---------------------------------------------------------------------
332 /// @todo document me
333 ::sal_Bool m_bInExecute
;
335 // handle to parent window
336 HWND m_hParentWindow
;
339 ::rtl::OUString m_sDirectory
;
342 ::rtl::OUString m_sFilename
;
345 CResourceProvider m_ResProvider
;
350 } // namespace fpicker
354 #endif // FPICKER_WIN32_VISTA_FILEPICKERIMPL_HXX