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>
22 #include "VistaFilePicker.hxx"
24 #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
;
369 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
:
371 bFileOpenDialog
= false;
372 nFeatures
|= FEATURE_AUTOEXTENSION
;
373 nFeatures
|= FEATURE_PASSWORD
;
374 nFeatures
|= FEATURE_FILTEROPTIONS
;
375 nFeatures
|= FEATURE_GPGPASSWORD
;
379 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION
:
381 bFileOpenDialog
= false;
382 nFeatures
|= FEATURE_AUTOEXTENSION
;
383 nFeatures
|= FEATURE_SELECTION
;
387 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE
:
389 bFileOpenDialog
= false;
390 nFeatures
|= FEATURE_AUTOEXTENSION
;
391 nFeatures
|= FEATURE_TEMPLATE
;
395 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE
:
397 bFileOpenDialog
= true;
398 nFeatures
|= FEATURE_LINK
;
399 nFeatures
|= FEATURE_PREVIEW
;
400 nFeatures
|= FEATURE_IMAGETEMPLATE
;
404 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR
:
406 bFileOpenDialog
= true;
407 nFeatures
|= FEATURE_LINK
;
408 nFeatures
|= FEATURE_PREVIEW
;
409 nFeatures
|= FEATURE_IMAGEANCHOR
;
413 case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY
:
415 bFileOpenDialog
= true;
416 nFeatures
|= FEATURE_PLAY
;
420 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PLAY
:
422 bFileOpenDialog
= true;
423 nFeatures
|= FEATURE_LINK
;
424 nFeatures
|= FEATURE_PLAY
;
428 case css::ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION
:
430 bFileOpenDialog
= true;
431 nFeatures
|= FEATURE_READONLY
;
432 nFeatures
|= FEATURE_VERSION
;
436 case css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW
:
438 bFileOpenDialog
= true;
439 nFeatures
|= FEATURE_LINK
;
440 nFeatures
|= FEATURE_PREVIEW
;
444 case css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION
:
446 bFileOpenDialog
= false;
447 nFeatures
|= FEATURE_AUTOEXTENSION
;
451 case css::ui::dialogs::TemplateDescription::FILEOPEN_PREVIEW
:
453 bFileOpenDialog
= true;
454 nFeatures
|= FEATURE_PREVIEW
;
458 css::uno::Reference
<css::awt::XWindow
> xParentWindow
;
459 if(lArguments
.getLength() > 1)
461 lArguments
[1] >>= xParentWindow
;
466 if (!m_bFolderPicker
)
467 rRequest
.setRequest(VistaFilePickerImpl::E_CREATE_OPEN_DIALOG
);
469 rRequest
.setRequest(VistaFilePickerImpl::E_CREATE_FOLDER_PICKER
);
472 rRequest
.setRequest (VistaFilePickerImpl::E_CREATE_SAVE_DIALOG
);
473 rRequest
.setArgument(PROP_FEATURES
, nFeatures
);
474 rRequest
.setArgument(PROP_TEMPLATE_DESCR
, nTemplate
);
475 if(xParentWindow
.is())
476 rRequest
.setArgument(PROP_PARENT_WINDOW
, xParentWindow
);
477 m_rDialog
.doRequest(rRequest
);
479 m_bInitialized
= true;
482 void SAL_CALL
VistaFilePicker::cancel()
486 OUString SAL_CALL
VistaFilePicker::getDirectory()
489 css::uno::Sequence
< OUString
> aFileSeq
= getSelectedFiles();
490 assert(aFileSeq
.getLength() <= 1);
491 return aFileSeq
.getLength() ? aFileSeq
[0] : OUString();
494 void SAL_CALL
VistaFilePicker::setDescription( const OUString
& aDescription
)
496 setTitle(aDescription
);
501 OUString SAL_CALL
VistaFilePicker::getImplementationName()
504 return "com.sun.star.ui.dialogs.Win32FolderPicker";
506 return "com.sun.star.ui.dialogs.Win32FilePicker";
509 sal_Bool SAL_CALL
VistaFilePicker::supportsService(const OUString
& sServiceName
)
511 return cppu::supportsService(this, sServiceName
);
514 css::uno::Sequence
< OUString
> SAL_CALL
VistaFilePicker::getSupportedServiceNames()
517 "com.sun.star.ui.dialogs.FilePicker",
518 "com.sun.star.ui.dialogs.SystemFilePicker",
519 "com.sun.star.ui.dialogs.SystemFolderPicker" };
524 } // namespace fpicker
526 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
527 fpicker_win32_FilePicker_get_implementation(
528 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
530 return cppu::acquire(new ::fpicker::win32::vista::VistaFilePicker(false));
533 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
534 fpicker_win32_FolderPicker_get_implementation(
535 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
537 return cppu::acquire(new ::fpicker::win32::vista::VistaFilePicker(true));
541 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */