tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / fpicker / source / win32 / VistaFilePicker.cxx
blobac35296f12fb7035abeb76690e142ec58b1e209f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <sal/config.h>
21 #include <config_gpgme.h>
23 #include "VistaFilePicker.hxx"
25 #include "WinImplHelper.hxx"
27 #include <com/sun/star/awt/XWindow.hpp>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
31 #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
32 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
34 #include <cppuhelper/interfacecontainer.h>
35 #include <cppuhelper/supportsservice.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <osl/file.hxx>
38 #include <officecfg/Office/Common.hxx>
40 #include <shlobj.h>
42 namespace fpicker{
43 namespace win32{
44 namespace vista{
46 VistaFilePicker::VistaFilePicker(bool bFolderPicker)
47 : TVistaFilePickerBase (m_aMutex )
48 , m_bInitialized (false )
49 , m_bFolderPicker (bFolderPicker )
53 VistaFilePicker::~VistaFilePicker()
57 void SAL_CALL VistaFilePicker::addFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener)
59 Request rRequest;
60 rRequest.setRequest (VistaFilePickerImpl::E_ADD_PICKER_LISTENER);
61 rRequest.setArgument(PROP_PICKER_LISTENER, xListener);
63 m_rDialog.doRequest(rRequest);
66 void SAL_CALL VistaFilePicker::removeFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener )
68 Request rRequest;
69 rRequest.setRequest (VistaFilePickerImpl::E_REMOVE_PICKER_LISTENER);
70 rRequest.setArgument(PROP_PICKER_LISTENER, xListener);
72 m_rDialog.doRequest(rRequest);
75 void VistaFilePicker::disposing(const css::lang::EventObject& /*aEvent*/)
79 void SAL_CALL VistaFilePicker::setMultiSelectionMode(sal_Bool bMode)
81 ensureInit();
83 Request rRequest;
84 rRequest.setRequest (VistaFilePickerImpl::E_SET_MULTISELECTION_MODE);
85 rRequest.setArgument(PROP_MULTISELECTION_MODE, bMode);
87 m_rDialog.doRequest(rRequest);
90 void SAL_CALL VistaFilePicker::setTitle(const OUString& sTitle)
92 ensureInit();
94 Request rRequest;
95 rRequest.setRequest (VistaFilePickerImpl::E_SET_TITLE);
96 rRequest.setArgument(PROP_TITLE, sTitle);
98 m_rDialog.doRequest(rRequest);
101 void SAL_CALL VistaFilePicker::appendFilter(const OUString& sTitle ,
102 const OUString& sFilter)
104 Request rRequest;
105 rRequest.setRequest (VistaFilePickerImpl::E_APPEND_FILTER);
106 rRequest.setArgument(PROP_FILTER_TITLE, sTitle );
107 rRequest.setArgument(PROP_FILTER_VALUE, sFilter);
109 m_rDialog.doRequest(rRequest);
112 void SAL_CALL VistaFilePicker::setCurrentFilter(const OUString& sTitle)
114 Request rRequest;
115 rRequest.setRequest (VistaFilePickerImpl::E_SET_CURRENT_FILTER);
116 rRequest.setArgument(PROP_FILTER_TITLE, sTitle);
118 m_rDialog.doRequest(rRequest);
121 OUString SAL_CALL VistaFilePicker::getCurrentFilter()
123 Request rRequest;
124 rRequest.setRequest (VistaFilePickerImpl::E_GET_CURRENT_FILTER);
126 m_rDialog.doRequest(rRequest);
128 const OUString sTitle = rRequest.getArgumentOrDefault(PROP_FILTER_TITLE, OUString());
129 return sTitle;
132 void SAL_CALL VistaFilePicker::appendFilterGroup(const OUString& /*sGroupTitle*/,
133 const css::uno::Sequence< css::beans::StringPair >& rFilters )
135 Request rRequest;
136 rRequest.setRequest (VistaFilePickerImpl::E_APPEND_FILTERGROUP);
137 rRequest.setArgument(PROP_FILTER_GROUP, rFilters);
139 m_rDialog.doRequest(rRequest);
142 void SAL_CALL VistaFilePicker::setDefaultName(const OUString& sName )
144 ensureInit();
146 Request rRequest;
147 rRequest.setRequest (VistaFilePickerImpl::E_SET_DEFAULT_NAME);
148 rRequest.setArgument(PROP_FILENAME, sName);
150 m_rDialog.doRequest(rRequest);
153 void SAL_CALL VistaFilePicker::setDisplayDirectory(const OUString& sDirectory)
155 ensureInit();
157 Request rRequest;
158 rRequest.setRequest (VistaFilePickerImpl::E_SET_DIRECTORY);
159 rRequest.setArgument(PROP_DIRECTORY, sDirectory);
161 m_rDialog.doRequest(rRequest);
164 OUString SAL_CALL VistaFilePicker::getDisplayDirectory()
166 ensureInit();
168 Request rRequest;
169 rRequest.setRequest (VistaFilePickerImpl::E_GET_DIRECTORY);
170 m_rDialog.doRequest(rRequest);
171 const OUString sDirectory = rRequest.getArgumentOrDefault(PROP_DIRECTORY, OUString());
173 return sDirectory;
176 // @deprecated can't be supported any longer ... see IDL description for further details
177 css::uno::Sequence< OUString > SAL_CALL VistaFilePicker::getFiles()
179 css::uno::Sequence< OUString > lFiles = getSelectedFiles();
180 // multiselection doesn't really work
181 // so just retrieve the first url
182 if (lFiles.getLength() > 1)
183 lFiles.realloc(1);
184 m_lLastFiles = lFiles;
185 return lFiles;
188 css::uno::Sequence< OUString > SAL_CALL VistaFilePicker::getSelectedFiles()
190 Request rRequest;
191 rRequest.setRequest (VistaFilePickerImpl::E_GET_SELECTED_FILES);
193 m_rDialog.doRequest(rRequest);
195 const css::uno::Sequence< OUString > lFiles = rRequest.getArgumentOrDefault(PROP_SELECTED_FILES, css::uno::Sequence< OUString >());
196 m_lLastFiles = lFiles;
197 return lFiles;
200 void VistaFilePicker::ensureInit()
202 if ( !m_bInitialized )
204 if (m_bFolderPicker)
206 Request rRequest;
207 rRequest.setRequest (VistaFilePickerImpl::E_CREATE_FOLDER_PICKER);
208 m_rDialog.doRequest(rRequest);
209 m_bInitialized = true;
211 else
213 initialize( { css::uno::Any(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE) });
218 ::sal_Int16 SAL_CALL VistaFilePicker::execute()
220 ensureInit();
222 Request rRequest;
223 rRequest.setRequest (VistaFilePickerImpl::E_SHOW_DIALOG_MODAL);
225 // show a modal window
226 m_rDialog.doRequest(rRequest);
228 const bool bOK = rRequest.getArgumentOrDefault(PROP_DIALOG_SHOW_RESULT, false );
229 m_lLastFiles = rRequest.getArgumentOrDefault(PROP_SELECTED_FILES , css::uno::Sequence< OUString >());
231 ::sal_Int16 nResult = css::ui::dialogs::ExecutableDialogResults::CANCEL;
232 if (bOK)
233 nResult = css::ui::dialogs::ExecutableDialogResults::OK;
234 return nResult;
237 // XFilePicker
239 void SAL_CALL VistaFilePicker::setValue( ::sal_Int16 nControlId ,
240 ::sal_Int16 nControlAction,
241 const css::uno::Any& aValue )
243 Request rRequest;
244 rRequest.setRequest (VistaFilePickerImpl::E_SET_CONTROL_VALUE);
245 rRequest.setArgument(PROP_CONTROL_ID , nControlId );
246 rRequest.setArgument(PROP_CONTROL_ACTION, nControlAction);
247 rRequest.setArgument(PROP_CONTROL_VALUE , aValue );
249 m_rDialog.doRequest(rRequest);
252 css::uno::Any SAL_CALL VistaFilePicker::getValue(::sal_Int16 nControlId ,
253 ::sal_Int16 nControlAction)
255 Request rRequest;
256 rRequest.setRequest (VistaFilePickerImpl::E_GET_CONTROL_VALUE);
257 rRequest.setArgument(PROP_CONTROL_ID , nControlId );
258 rRequest.setArgument(PROP_CONTROL_ACTION, nControlAction);
260 m_rDialog.doRequest(rRequest);
261 return rRequest.getValue(PROP_CONTROL_VALUE);
264 void SAL_CALL VistaFilePicker::enableControl(::sal_Int16 nControlId,
265 sal_Bool bEnable )
267 Request rRequest;
268 rRequest.setRequest (VistaFilePickerImpl::E_ENABLE_CONTROL);
269 rRequest.setArgument(PROP_CONTROL_ID , nControlId);
270 rRequest.setArgument(PROP_CONTROL_ENABLE, bEnable );
272 m_rDialog.doRequest(rRequest);
275 void SAL_CALL VistaFilePicker::setLabel( ::sal_Int16 nControlId,
276 const OUString& sLabel )
278 Request rRequest;
279 rRequest.setRequest (VistaFilePickerImpl::E_SET_CONTROL_LABEL);
280 rRequest.setArgument(PROP_CONTROL_ID , nControlId);
281 rRequest.setArgument(PROP_CONTROL_LABEL, sLabel );
283 m_rDialog.doRequest(rRequest);
286 OUString SAL_CALL VistaFilePicker::getLabel(::sal_Int16 nControlId)
288 Request rRequest;
289 rRequest.setRequest (VistaFilePickerImpl::E_GET_CONTROL_LABEL);
290 rRequest.setArgument(PROP_CONTROL_ID, nControlId);
292 m_rDialog.doRequest(rRequest);
293 const OUString sLabel = rRequest.getArgumentOrDefault(PROP_CONTROL_LABEL, OUString());
294 return sLabel;
297 css::uno::Sequence< ::sal_Int16 > SAL_CALL VistaFilePicker::getSupportedImageFormats()
299 return css::uno::Sequence< sal_Int16 >();
302 sal_Int32 SAL_CALL VistaFilePicker::getTargetColorDepth()
304 return 0;
307 sal_Int32 SAL_CALL VistaFilePicker::getAvailableWidth()
309 return 0;
312 sal_Int32 SAL_CALL VistaFilePicker::getAvailableHeight()
314 return 0;
317 void SAL_CALL VistaFilePicker::setImage( sal_Int16 /*nImageFormat*/,
318 const css::uno::Any& /*aImage */)
322 sal_Bool SAL_CALL VistaFilePicker::setShowState(sal_Bool /*bShowState*/)
324 return false;
327 sal_Bool SAL_CALL VistaFilePicker::getShowState()
329 return false;
332 void SAL_CALL VistaFilePicker::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
334 if (lArguments.getLength() < 1)
335 throw css::lang::IllegalArgumentException(
336 "XInitialization::initialize() called without arguments.",
337 static_cast< css::ui::dialogs::XFilePicker2* >( this ),
340 sal_Int32 nTemplate = -1;
341 lArguments[0] >>= nTemplate;
343 bool bFileOpenDialog = true;
344 ::sal_Int32 nFeatures = 0;
346 switch(nTemplate)
348 case css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE :
350 bFileOpenDialog = true;
352 break;
354 case css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE :
356 bFileOpenDialog = false;
358 break;
360 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD :
362 bFileOpenDialog = false;
363 nFeatures |= FEATURE_AUTOEXTENSION;
364 nFeatures |= FEATURE_PASSWORD;
365 nFeatures |= FEATURE_GPGPASSWORD;
366 #if HAVE_FEATURE_GPGME
367 nFeatures |= FEATURE_GPGSIGN;
368 #endif
370 break;
372 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS :
374 bFileOpenDialog = false;
375 nFeatures |= FEATURE_AUTOEXTENSION;
376 nFeatures |= FEATURE_PASSWORD;
377 nFeatures |= FEATURE_FILTEROPTIONS;
378 nFeatures |= FEATURE_GPGPASSWORD;
379 #if HAVE_FEATURE_GPGME
380 nFeatures |= FEATURE_GPGSIGN;
381 #endif
383 break;
385 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION :
387 bFileOpenDialog = false;
388 nFeatures |= FEATURE_AUTOEXTENSION;
389 nFeatures |= FEATURE_SELECTION;
391 break;
393 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE :
395 bFileOpenDialog = false;
396 nFeatures |= FEATURE_AUTOEXTENSION;
397 nFeatures |= FEATURE_TEMPLATE;
399 break;
401 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE :
403 bFileOpenDialog = true;
404 nFeatures |= FEATURE_LINK;
405 nFeatures |= FEATURE_PREVIEW;
406 nFeatures |= FEATURE_IMAGETEMPLATE;
408 break;
410 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR :
412 bFileOpenDialog = true;
413 nFeatures |= FEATURE_LINK;
414 nFeatures |= FEATURE_PREVIEW;
415 nFeatures |= FEATURE_IMAGEANCHOR;
417 break;
419 case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY :
421 bFileOpenDialog = true;
422 nFeatures |= FEATURE_PLAY;
424 break;
426 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PLAY :
428 bFileOpenDialog = true;
429 nFeatures |= FEATURE_LINK;
430 nFeatures |= FEATURE_PLAY;
432 break;
434 case css::ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION :
436 bFileOpenDialog = true;
437 nFeatures |= FEATURE_READONLY;
438 nFeatures |= FEATURE_VERSION;
440 break;
442 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW :
444 bFileOpenDialog = true;
445 nFeatures |= FEATURE_LINK;
446 nFeatures |= FEATURE_PREVIEW;
448 break;
450 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION :
452 bFileOpenDialog = false;
453 nFeatures |= FEATURE_AUTOEXTENSION;
455 break;
457 case css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW :
459 bFileOpenDialog = true;
460 nFeatures |= FEATURE_PREVIEW;
462 break;
464 css::uno::Reference<css::awt::XWindow> xParentWindow;
465 if(lArguments.getLength() > 1)
467 lArguments[1] >>= xParentWindow;
469 Request rRequest;
470 if (bFileOpenDialog)
472 if (!m_bFolderPicker)
473 rRequest.setRequest(VistaFilePickerImpl::E_CREATE_OPEN_DIALOG);
474 else
475 rRequest.setRequest(VistaFilePickerImpl::E_CREATE_FOLDER_PICKER);
477 else
478 rRequest.setRequest (VistaFilePickerImpl::E_CREATE_SAVE_DIALOG);
479 rRequest.setArgument(PROP_FEATURES, nFeatures);
480 rRequest.setArgument(PROP_TEMPLATE_DESCR, nTemplate);
481 if(xParentWindow.is())
482 rRequest.setArgument(PROP_PARENT_WINDOW, xParentWindow);
483 m_rDialog.doRequest(rRequest);
485 m_bInitialized = true;
488 void SAL_CALL VistaFilePicker::cancel()
492 OUString SAL_CALL VistaFilePicker::getDirectory()
494 ensureInit();
495 css::uno::Sequence< OUString > aFileSeq = getSelectedFiles();
496 assert(aFileSeq.getLength() <= 1);
497 return aFileSeq.getLength() ? aFileSeq[0] : OUString();
500 void SAL_CALL VistaFilePicker::setDescription( const OUString& aDescription )
502 setTitle(aDescription);
505 // XServiceInfo
507 OUString SAL_CALL VistaFilePicker::getImplementationName()
509 if (m_bFolderPicker)
510 return "com.sun.star.ui.dialogs.Win32FolderPicker";
511 else
512 return "com.sun.star.ui.dialogs.Win32FilePicker";
515 sal_Bool SAL_CALL VistaFilePicker::supportsService(const OUString& sServiceName)
517 return cppu::supportsService(this, sServiceName);
520 css::uno::Sequence< OUString > SAL_CALL VistaFilePicker::getSupportedServiceNames()
522 return {
523 "com.sun.star.ui.dialogs.FilePicker",
524 "com.sun.star.ui.dialogs.SystemFilePicker",
525 "com.sun.star.ui.dialogs.SystemFolderPicker" };
528 } // namespace vista
529 } // namespace win32
530 } // namespace fpicker
532 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
533 fpicker_win32_FilePicker_get_implementation(
534 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
536 return cppu::acquire(new ::fpicker::win32::vista::VistaFilePicker(false));
539 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
540 fpicker_win32_FolderPicker_get_implementation(
541 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
543 return cppu::acquire(new ::fpicker::win32::vista::VistaFilePicker(true));
547 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */