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 "VistaFilePickerEventHandler.hxx"
24 #include "requests.hxx"
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/embed/XStorage.hpp>
28 #include <com/sun/star/document/XDocumentRevisionListPersistence.hpp>
29 #include <com/sun/star/util/RevisionTag.hpp>
30 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
31 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
33 #include <osl/file.hxx>
36 // namespace directives
44 VistaFilePickerEventHandler::VistaFilePickerEventHandler(IVistaFilePickerInternalNotify
* pInternalNotify
)
46 , m_nListenerHandle (0 )
48 , m_pInternalNotify (pInternalNotify
)
49 , m_lListener (m_aMutex
)
54 VistaFilePickerEventHandler::~VistaFilePickerEventHandler()
59 HRESULT STDMETHODCALLTYPE
VistaFilePickerEventHandler::QueryInterface(REFIID rIID
,
64 if ( rIID
== IID_IUnknown
)
65 *ppObject
= static_cast<IUnknown
*>(static_cast<IFileDialogEvents
*>(this));
67 if ( rIID
== IID_IFileDialogEvents
)
68 *ppObject
= static_cast<IFileDialogEvents
*>(this);
70 if ( rIID
== IID_IFileDialogControlEvents
)
71 *ppObject
= static_cast<IFileDialogControlEvents
*>(this);
73 if ( *ppObject
!= nullptr )
75 static_cast<IUnknown
*>(*ppObject
)->AddRef();
83 ULONG STDMETHODCALLTYPE
VistaFilePickerEventHandler::AddRef()
85 return osl_atomic_increment(&m_nRefCount
);
89 ULONG STDMETHODCALLTYPE
VistaFilePickerEventHandler::Release()
91 ULONG nReturn
= --m_nRefCount
;
92 if ( m_nRefCount
== 0 )
99 STDMETHODIMP
VistaFilePickerEventHandler::OnFileOk(IFileDialog
* /*pDialog*/)
105 STDMETHODIMP
VistaFilePickerEventHandler::OnFolderChanging(IFileDialog
* /*pDialog*/,
106 IShellItem
* /*pFolder*/)
112 STDMETHODIMP
VistaFilePickerEventHandler::OnFolderChange(IFileDialog
* /*pDialog*/)
114 impl_sendEvent(E_DIRECTORY_CHANGED
, 0);
115 m_pInternalNotify
->onDirectoryChanged();
120 STDMETHODIMP
VistaFilePickerEventHandler::OnSelectionChange(IFileDialog
* /*pDialog*/)
122 impl_sendEvent(E_FILE_SELECTION_CHANGED
, 0);
127 STDMETHODIMP
VistaFilePickerEventHandler::OnShareViolation(IFileDialog
* /*pDialog*/ ,
129 IShellItem
* /*pItem*/ ,
131 FDE_SHAREVIOLATION_RESPONSE
* /*pResponse*/)
133 impl_sendEvent(E_CONTROL_STATE_CHANGED
, css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER
);
138 STDMETHODIMP
VistaFilePickerEventHandler::OnTypeChange(IFileDialog
* pDialog
)
141 HRESULT hResult
= pDialog
->GetFileTypeIndex( &nFileTypeIndex
);
143 if ( hResult
== S_OK
)
145 if ( m_pInternalNotify
->onFileTypeChanged( nFileTypeIndex
))
146 impl_sendEvent(E_CONTROL_STATE_CHANGED
, css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER
);
153 STDMETHODIMP
VistaFilePickerEventHandler::OnOverwrite(IFileDialog
* /*pDialog*/ ,
154 IShellItem
* /*pItem*/ ,
155 FDE_OVERWRITE_RESPONSE
* /*pResponse*/)
161 STDMETHODIMP
VistaFilePickerEventHandler::OnItemSelected(IFileDialogCustomize
* /*pCustomize*/,
168 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
173 STDMETHODIMP
VistaFilePickerEventHandler::OnButtonClicked(IFileDialogCustomize
* /*pCustomize*/,
177 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
182 STDMETHODIMP
VistaFilePickerEventHandler::OnCheckButtonToggled(IFileDialogCustomize
* /*pCustomize*/,
186 if (nIDCtl
== css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION
)
187 m_pInternalNotify
->onAutoExtensionChanged(bChecked
);
189 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
195 STDMETHODIMP
VistaFilePickerEventHandler::OnControlActivating(IFileDialogCustomize
* /*pCustomize*/,
198 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
203 void VistaFilePickerEventHandler::addFilePickerListener( const css::uno::Reference
< css::ui::dialogs::XFilePickerListener
>& xListener
)
205 m_lListener
.addInterface(cppu::UnoType
<css::ui::dialogs::XFilePickerListener
>::get(), xListener
);
209 void VistaFilePickerEventHandler::removeFilePickerListener( const css::uno::Reference
< css::ui::dialogs::XFilePickerListener
>& xListener
)
211 m_lListener
.removeInterface(cppu::UnoType
<css::ui::dialogs::XFilePickerListener
>::get(), xListener
);
215 void VistaFilePickerEventHandler::startListening( const TFileDialog
& pBroadcaster
)
220 m_pDialog
= pBroadcaster
;
221 m_pDialog
->Advise(this, &m_nListenerHandle
);
225 void VistaFilePickerEventHandler::stopListening()
229 m_pDialog
->Unadvise(m_nListenerHandle
);
234 constexpr OUString PROP_CONTROL_ID
= u
"control_id"_ustr
;
235 constexpr OUString PROP_PICKER_LISTENER
= u
"picker_listener"_ustr
;
239 void doRequest(Request
& rRequest
)
241 const ::sal_Int32 nEventID
= rRequest
.getRequest();
242 const ::sal_Int16 nControlID
= rRequest
.getArgumentOrDefault(PROP_CONTROL_ID
, ::sal_Int16(0));
243 const css::uno::Reference
< css::ui::dialogs::XFilePickerListener
> xListener
= rRequest
.getArgumentOrDefault(PROP_PICKER_LISTENER
, css::uno::Reference
< css::ui::dialogs::XFilePickerListener
>());
245 if ( ! xListener
.is())
248 css::ui::dialogs::FilePickerEvent aEvent
;
249 aEvent
.ElementId
= nControlID
;
253 case VistaFilePickerEventHandler::E_FILE_SELECTION_CHANGED
:
254 xListener
->fileSelectionChanged(aEvent
);
257 case VistaFilePickerEventHandler::E_DIRECTORY_CHANGED
:
258 xListener
->directoryChanged(aEvent
);
261 case VistaFilePickerEventHandler::E_HELP_REQUESTED
:
262 xListener
->helpRequested(aEvent
);
265 case VistaFilePickerEventHandler::E_CONTROL_STATE_CHANGED
:
266 xListener
->controlStateChanged(aEvent
);
269 case VistaFilePickerEventHandler::E_DIALOG_SIZE_CHANGED
:
270 xListener
->dialogSizeChanged();
273 // no default here. Let compiler detect changes on enum set !
279 void VistaFilePickerEventHandler::impl_sendEvent( EEventType eEventType
,
280 ::sal_Int16 nControlID
)
282 comphelper::OInterfaceContainerHelper2
* pContainer
= m_lListener
.getContainer( cppu::UnoType
<css::ui::dialogs::XFilePickerListener
>::get());
286 comphelper::OInterfaceIteratorHelper2
pIterator(*pContainer
);
287 while (pIterator
.hasMoreElements())
291 css::uno::Reference
< css::ui::dialogs::XFilePickerListener
> xListener (
292 static_cast< css::ui::dialogs::XFilePickerListener
* >(pIterator
.next()));
295 rRequest
.setRequest (eEventType
);
296 rRequest
.setArgument(PROP_PICKER_LISTENER
, xListener
);
298 rRequest
.setArgument(PROP_CONTROL_ID
, nControlID
);
302 catch(const css::uno::RuntimeException
&)
311 } // namespace fpicker
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */