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 #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>
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
)
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
)
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
)
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
)
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
)
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
)
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()
124 rRequest
.setRequest (VistaFilePickerImpl::E_GET_CURRENT_FILTER
);
126 m_rDialog
.doRequest(rRequest
);
128 const OUString sTitle
= rRequest
.getArgumentOrDefault(PROP_FILTER_TITLE
, OUString());
132 void SAL_CALL
VistaFilePicker::appendFilterGroup(const OUString
& /*sGroupTitle*/,
133 const css::uno::Sequence
< css::beans::StringPair
>& rFilters
)
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
)
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
)
158 rRequest
.setRequest (VistaFilePickerImpl::E_SET_DIRECTORY
);
159 rRequest
.setArgument(PROP_DIRECTORY
, sDirectory
);
161 m_rDialog
.doRequest(rRequest
);
164 OUString SAL_CALL
VistaFilePicker::getDisplayDirectory()
169 rRequest
.setRequest (VistaFilePickerImpl::E_GET_DIRECTORY
);
170 m_rDialog
.doRequest(rRequest
);
171 const OUString sDirectory
= rRequest
.getArgumentOrDefault(PROP_DIRECTORY
, OUString());
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)
184 m_lLastFiles
= lFiles
;
188 css::uno::Sequence
< OUString
> SAL_CALL
VistaFilePicker::getSelectedFiles()
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
;
200 void VistaFilePicker::ensureInit()
202 if ( !m_bInitialized
)
207 rRequest
.setRequest (VistaFilePickerImpl::E_CREATE_FOLDER_PICKER
);
208 m_rDialog
.doRequest(rRequest
);
209 m_bInitialized
= true;
213 initialize( { css::uno::Any(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
) });
218 ::sal_Int16 SAL_CALL
VistaFilePicker::execute()
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
;
233 nResult
= css::ui::dialogs::ExecutableDialogResults::OK
;
239 void SAL_CALL
VistaFilePicker::setValue( ::sal_Int16 nControlId
,
240 ::sal_Int16 nControlAction
,
241 const css::uno::Any
& aValue
)
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
)
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
,
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
)
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
)
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());
297 css::uno::Sequence
< ::sal_Int16
> SAL_CALL
VistaFilePicker::getSupportedImageFormats()
299 return css::uno::Sequence
< sal_Int16
>();
302 sal_Int32 SAL_CALL
VistaFilePicker::getTargetColorDepth()
307 sal_Int32 SAL_CALL
VistaFilePicker::getAvailableWidth()
312 sal_Int32 SAL_CALL
VistaFilePicker::getAvailableHeight()
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*/)
327 sal_Bool SAL_CALL
VistaFilePicker::getShowState()
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;
348 case css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
:
350 bFileOpenDialog
= true;
354 case css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
:
356 bFileOpenDialog
= false;
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
;
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
;
385 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION
:
387 bFileOpenDialog
= false;
388 nFeatures
|= FEATURE_AUTOEXTENSION
;
389 nFeatures
|= FEATURE_SELECTION
;
393 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE
:
395 bFileOpenDialog
= false;
396 nFeatures
|= FEATURE_AUTOEXTENSION
;
397 nFeatures
|= FEATURE_TEMPLATE
;
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
;
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
;
419 case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY
:
421 bFileOpenDialog
= true;
422 nFeatures
|= FEATURE_PLAY
;
426 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PLAY
:
428 bFileOpenDialog
= true;
429 nFeatures
|= FEATURE_LINK
;
430 nFeatures
|= FEATURE_PLAY
;
434 case css::ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION
:
436 bFileOpenDialog
= true;
437 nFeatures
|= FEATURE_READONLY
;
438 nFeatures
|= FEATURE_VERSION
;
442 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW
:
444 bFileOpenDialog
= true;
445 nFeatures
|= FEATURE_LINK
;
446 nFeatures
|= FEATURE_PREVIEW
;
450 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION
:
452 bFileOpenDialog
= false;
453 nFeatures
|= FEATURE_AUTOEXTENSION
;
457 case css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW
:
459 bFileOpenDialog
= true;
460 nFeatures
|= FEATURE_PREVIEW
;
464 css::uno::Reference
<css::awt::XWindow
> xParentWindow
;
465 if(lArguments
.getLength() > 1)
467 lArguments
[1] >>= xParentWindow
;
472 if (!m_bFolderPicker
)
473 rRequest
.setRequest(VistaFilePickerImpl::E_CREATE_OPEN_DIALOG
);
475 rRequest
.setRequest(VistaFilePickerImpl::E_CREATE_FOLDER_PICKER
);
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()
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
);
507 OUString SAL_CALL
VistaFilePicker::getImplementationName()
510 return "com.sun.star.ui.dialogs.Win32FolderPicker";
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()
523 "com.sun.star.ui.dialogs.FilePicker",
524 "com.sun.star.ui.dialogs.SystemFilePicker",
525 "com.sun.star.ui.dialogs.SystemFolderPicker" };
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: */