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 .
22 #include "platform_vista.h"
26 #include "requests.hxx"
27 #include "vistatypes.h"
28 #include "FilterContainer.hxx"
29 #include "VistaFilePickerEventHandler.hxx"
30 #include "IVistaFilePickerInternalNotify.hxx"
31 #include "resourceprovider.hxx"
33 #include <cppuhelper/interfacecontainer.h>
34 #include <osl/thread.hxx>
35 #include <osl/conditn.hxx>
36 #include <rtl/ustring.hxx>
46 const ::sal_Int32 FEATURE_AUTOEXTENSION
= 1;
47 const ::sal_Int32 FEATURE_PASSWORD
= 2;
48 const ::sal_Int32 FEATURE_FILTEROPTIONS
= 4;
49 const ::sal_Int32 FEATURE_SELECTION
= 8;
50 const ::sal_Int32 FEATURE_TEMPLATE
= 16;
51 const ::sal_Int32 FEATURE_LINK
= 32;
52 const ::sal_Int32 FEATURE_PREVIEW
= 64;
53 const ::sal_Int32 FEATURE_IMAGETEMPLATE
= 128;
54 const ::sal_Int32 FEATURE_PLAY
= 256;
55 const ::sal_Int32 FEATURE_READONLY
= 512;
56 const ::sal_Int32 FEATURE_VERSION
= 1024;
57 const ::sal_Int32 FEATURE_GPGPASSWORD
= 2048;
58 const ::sal_Int32 FEATURE_IMAGEANCHOR
= 4096;
59 const ::sal_Int32 FEATURE_GPGSIGN
= 8192;
61 inline constexpr OUString
PROP_PICKER_LISTENER(u
"picker_listener"_ustr
); // [XFilePickerListenert]
62 inline constexpr OUString
PROP_DIALOG_SHOW_RESULT(u
"dialog_show_result"_ustr
); // [sal_Bool] true=OK, false=CANCEL
63 inline constexpr OUString
PROP_SELECTED_FILES(u
"selected_files"_ustr
); // [seq< OUString >] contains all user selected files (can be empty!)
64 inline constexpr OUString
PROP_MULTISELECTION_MODE(u
"multiselection_mode"_ustr
); // [sal_Bool] true=ON, false=OFF
65 inline constexpr OUString
PROP_TITLE(u
"title"_ustr
); // [OUString]
66 inline constexpr OUString
PROP_FILENAME(u
"filename"_ustr
); // [OUString]
67 inline constexpr OUString
PROP_DIRECTORY(u
"directory"_ustr
); // [OUString]
68 inline constexpr OUString
PROP_FEATURES(u
"features"_ustr
); // [sal_Int32]
69 inline constexpr OUString
PROP_TEMPLATE_DESCR(u
"templatedescription"_ustr
); // [sal_Int32]
70 inline constexpr OUString
PROP_FILTER_TITLE(u
"filter_title"_ustr
); // [OUString]
71 inline constexpr OUString
PROP_FILTER_VALUE(u
"filter_value"_ustr
); // [OUString]
72 inline constexpr OUString
PROP_FILTER_GROUP(u
"filter-group"_ustr
); // [seq< css:beans::StringPair >] contains a group of filters
74 inline constexpr OUString
PROP_CONTROL_ID(u
"control_id"_ustr
); // [sal_Int16]
75 inline constexpr OUString
PROP_CONTROL_ACTION(u
"control_action"_ustr
); // [sal_Int16]
76 inline constexpr OUString
PROP_CONTROL_VALUE(u
"control_value"_ustr
); // [Any]
77 inline constexpr OUString
PROP_CONTROL_LABEL(u
"control_label"_ustr
); // [OUString]
78 inline constexpr OUString
PROP_CONTROL_ENABLE(u
"control_enable"_ustr
); // [sal_Bool] true=ON, false=OFF
79 inline constexpr OUString
PROP_PARENT_WINDOW(u
"ParentWindow"_ustr
); //[css::awt::XWindow] preferred parent window
80 inline constexpr OUString
STRING_SEPARATOR(u
"------------------------------------------"_ustr
);
82 class TDialogImplBase
;
84 /** native implementation of the file picker on Vista and upcoming windows versions.
85 * This dialog uses COM internally. Further it marshall every request so it will
86 * be executed on the main thread which is an STA thread !
89 class VistaFilePickerImpl
: public IVistaFilePickerInternalNotify
93 // Workaround made to get input in Template Listbox
94 css::uno::Sequence
< OUString
> m_lItems
;
95 /** used for marshalling requests.
96 * Will be used to map requests to the right implementations.
101 E_ADD_PICKER_LISTENER
,
102 E_REMOVE_PICKER_LISTENER
,
104 E_SET_CURRENT_FILTER
,
105 E_GET_CURRENT_FILTER
,
106 E_CREATE_OPEN_DIALOG
,
107 E_CREATE_SAVE_DIALOG
,
108 E_CREATE_FOLDER_PICKER
,
109 E_SET_MULTISELECTION_MODE
,
115 E_GET_SELECTED_FILES
,
128 // ctor/dtor - nothing special
130 VistaFilePickerImpl();
131 virtual ~VistaFilePickerImpl();
136 void doRequest(Request
& rRequest
);
139 // IVistaFilePickerInternalNotify
141 virtual void onAutoExtensionChanged (bool bChecked
) override
;
142 virtual bool onFileTypeChanged( UINT nTypeIndex
) override
;
143 virtual void onDirectoryChanged() override
;
146 OUString
GetDirectory();
148 /// implementation of request E_ADD_FILEPICKER_LISTENER
149 void impl_sta_addFilePickerListener(Request
& rRequest
);
152 /// implementation of request E_REMOVE_FILEPICKER_LISTENER
153 void impl_sta_removeFilePickerListener(Request
& rRequest
);
156 /// implementation of request E_APPEND_FILTER
157 void impl_sta_appendFilter(Request
& rRequest
);
160 /// implementation of request E_APPEND_FILTERGROUP
161 void impl_sta_appendFilterGroup(Request
& rRequest
);
164 /// implementation of request E_SET_CURRENT_FILTER
165 void impl_sta_setCurrentFilter(Request
& rRequest
);
168 /// implementation of request E_GET_CURRENT_FILTER
169 void impl_sta_getCurrentFilter(Request
& rRequest
);
172 /// implementation of request E_CREATE_OPEN_DIALOG
173 void impl_sta_CreateOpenDialog(Request
& rRequest
);
176 /// implementation of request E_CREATE_SAVE_DIALOG
177 void impl_sta_CreateSaveDialog(Request
& rRequest
);
180 /// implementation of request E_CREATE_FOLDER_PICKER
181 void impl_sta_CreateFolderPicker(Request
& rRequest
);
184 /// implementation of request E_SET_MULTISELECTION_MODE
185 void impl_sta_SetMultiSelectionMode(Request
& rRequest
);
188 /// implementation of request E_SET_TITLE
189 void impl_sta_SetTitle(Request
& rRequest
);
192 /// implementation of request E_SET_FILENAME
193 void impl_sta_SetFileName(Request
& rRequest
);
196 /// implementation of request E_SET_DIRECTORY
197 void impl_sta_SetDirectory(Request
& rRequest
);
200 /// implementation of request E_GET_DIRECTORY
201 void impl_sta_GetDirectory(Request
& rRequest
);
204 /// implementation of request E_SET_DEFAULT_NAME
205 void impl_sta_SetDefaultName(Request
& rRequest
);
208 /// implementation of request E_GET_SELECTED_FILES
209 void impl_sta_getSelectedFiles(Request
& rRequest
);
212 /// implementation of request E_SHOW_DIALOG_MODAL
213 void impl_sta_ShowDialogModal(Request
& rRequest
);
216 /// implementation of request E_SET_CONTROL_VALUE
217 void impl_sta_SetControlValue(Request
& rRequest
);
220 /// implementation of request E_GET_CONTROL_VALUE
221 void impl_sta_GetControlValue(Request
& rRequest
);
224 /// implementation of request E_SET_CONTROL_LABEL
225 void impl_sta_SetControlLabel(Request
& rRequest
);
228 /// implementation of request E_GET_CONTROL_LABEL
229 static void impl_sta_GetControlLabel(Request
& rRequest
);
232 /// implementation of request E_ENABLE_CONTROL
233 void impl_sta_EnableControl(Request
& rRequest
);
235 /** create all needed (optional!) UI controls addressed by the field nFeatures.
236 * The given number nFeatures is used as a flag field. Use const values FEATURE_XXX
239 * Internal new controls will be added to the dialog. Every control can be accessed
240 * by its own control id. Those control ID must be one of the const set
241 * css::ui::dialogs::ExtendedFilePickerElementIds.
243 * @see setControlValue()
244 * @see getControlValue()
245 * @see setControlLabel()
246 * @see getControlLabel()
247 * @see enableControl()
250 * flag field(!) knows all features which must be enabled.
252 void impl_sta_enableFeatures(::sal_Int32 nFeatures
, ::sal_Int32 nTemplate
);
255 /** returns an interface, which can be used to customize the internally used
258 * Because we use two member (open/save dialog) internally, this method
259 * ask the current active one for its customization interface.
261 * @return the customization interface for the current used dialog.
264 TFileDialogCustomize
impl_getCustomizeInterface();
265 TFileDialog
impl_getBaseDialogInterface();
268 /// fill filter list of internal used dialog.
269 void impl_sta_setFiltersOnDialog();
271 void impl_SetDefaultExtension( const OUString
& currentFilter
);
274 template <class TDialogImplClass
> void impl_sta_CreateDialog();
275 void impl_sta_InitDialog(Request
& rRequest
, DWORD nOrFlags
);
278 /// object representing a file dialog
279 std::shared_ptr
<TDialogImplBase
> m_pDialog
;
282 /// @todo document me
283 CFilterContainer m_lFilters
;
286 /** help us to handle dialog events and provide them to interested office
289 TFileDialogEvents m_iEventHandler
;
292 /// @todo document me
297 // handle to parent window
298 HWND m_hParentWindow
;
301 OUString m_sDirectory
;
304 OUString m_sFilename
;
309 } // namespace fpicker
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */