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 .
21 #include "VistaFilePickerEventHandler.hxx"
23 #include "asyncrequests.hxx"
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/embed/XStorage.hpp>
27 #include <com/sun/star/document/XDocumentRevisionListPersistence.hpp>
28 #include <com/sun/star/util/RevisionTag.hpp>
29 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
30 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
32 #include <osl/file.hxx>
35 // namespace directives
43 VistaFilePickerEventHandler::VistaFilePickerEventHandler(IVistaFilePickerInternalNotify
* pInternalNotify
)
45 , m_nListenerHandle (0 )
47 , m_pInternalNotify (pInternalNotify
)
48 , m_lListener (m_aMutex
)
53 VistaFilePickerEventHandler::~VistaFilePickerEventHandler()
58 HRESULT STDMETHODCALLTYPE
VistaFilePickerEventHandler::QueryInterface(REFIID rIID
,
63 if ( rIID
== IID_IUnknown
)
64 *ppObject
= static_cast<IUnknown
*>(static_cast<IFileDialogEvents
*>(this));
66 if ( rIID
== IID_IFileDialogEvents
)
67 *ppObject
= static_cast<IFileDialogEvents
*>(this);
69 if ( rIID
== IID_IFileDialogControlEvents
)
70 *ppObject
= static_cast<IFileDialogControlEvents
*>(this);
72 if ( *ppObject
!= nullptr )
74 static_cast<IUnknown
*>(*ppObject
)->AddRef();
82 ULONG STDMETHODCALLTYPE
VistaFilePickerEventHandler::AddRef()
84 return osl_atomic_increment(&m_nRefCount
);
88 ULONG STDMETHODCALLTYPE
VistaFilePickerEventHandler::Release()
90 ULONG nReturn
= --m_nRefCount
;
91 if ( m_nRefCount
== 0 )
98 STDMETHODIMP
VistaFilePickerEventHandler::OnFileOk(IFileDialog
* /*pDialog*/)
104 STDMETHODIMP
VistaFilePickerEventHandler::OnFolderChanging(IFileDialog
* /*pDialog*/,
105 IShellItem
* /*pFolder*/)
111 STDMETHODIMP
VistaFilePickerEventHandler::OnFolderChange(IFileDialog
* /*pDialog*/)
113 impl_sendEvent(E_DIRECTORY_CHANGED
, 0);
118 STDMETHODIMP
VistaFilePickerEventHandler::OnSelectionChange(IFileDialog
* /*pDialog*/)
120 impl_sendEvent(E_FILE_SELECTION_CHANGED
, 0);
125 STDMETHODIMP
VistaFilePickerEventHandler::OnShareViolation(IFileDialog
* /*pDialog*/ ,
127 IShellItem
* /*pItem*/ ,
129 FDE_SHAREVIOLATION_RESPONSE
* /*pResponse*/)
131 impl_sendEvent(E_CONTROL_STATE_CHANGED
, css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER
);
136 STDMETHODIMP
VistaFilePickerEventHandler::OnTypeChange(IFileDialog
* pDialog
)
139 HRESULT hResult
= pDialog
->GetFileTypeIndex( &nFileTypeIndex
);
141 if ( hResult
== S_OK
)
143 if ( m_pInternalNotify
->onFileTypeChanged( nFileTypeIndex
))
144 impl_sendEvent(E_CONTROL_STATE_CHANGED
, css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER
);
151 STDMETHODIMP
VistaFilePickerEventHandler::OnOverwrite(IFileDialog
* /*pDialog*/ ,
152 IShellItem
* /*pItem*/ ,
153 FDE_OVERWRITE_RESPONSE
* /*pResponse*/)
159 STDMETHODIMP
VistaFilePickerEventHandler::OnItemSelected(IFileDialogCustomize
* /*pCustomize*/,
166 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
171 STDMETHODIMP
VistaFilePickerEventHandler::OnButtonClicked(IFileDialogCustomize
* /*pCustomize*/,
175 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
180 STDMETHODIMP
VistaFilePickerEventHandler::OnCheckButtonToggled(IFileDialogCustomize
* /*pCustomize*/,
184 if (nIDCtl
== css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION
)
185 m_pInternalNotify
->onAutoExtensionChanged(bChecked
);
187 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
193 STDMETHODIMP
VistaFilePickerEventHandler::OnControlActivating(IFileDialogCustomize
* /*pCustomize*/,
196 impl_sendEvent(E_CONTROL_STATE_CHANGED
, static_cast<sal_Int16
>( nIDCtl
));
201 void VistaFilePickerEventHandler::addFilePickerListener( const css::uno::Reference
< css::ui::dialogs::XFilePickerListener
>& xListener
)
203 m_lListener
.addInterface(cppu::UnoType
<css::ui::dialogs::XFilePickerListener
>::get(), xListener
);
207 void VistaFilePickerEventHandler::removeFilePickerListener( const css::uno::Reference
< css::ui::dialogs::XFilePickerListener
>& xListener
)
209 m_lListener
.removeInterface(cppu::UnoType
<css::ui::dialogs::XFilePickerListener
>::get(), xListener
);
213 void VistaFilePickerEventHandler::startListening( const TFileDialog
& pBroadcaster
)
218 m_pDialog
= pBroadcaster
;
219 m_pDialog
->Advise(this, &m_nListenerHandle
);
223 void VistaFilePickerEventHandler::stopListening()
227 m_pDialog
->Unadvise(m_nListenerHandle
);
232 static const char PROP_CONTROL_ID
[] = "control_id";
233 static const char PROP_PICKER_LISTENER
[] = "picker_listener";
236 class AsyncPickerEvents
: public RequestHandler
243 virtual void before() override
246 virtual void doRequest(const RequestRef
& rRequest
) override
248 const ::sal_Int32 nEventID
= rRequest
->getRequest();
249 const ::sal_Int16 nControlID
= rRequest
->getArgumentOrDefault(PROP_CONTROL_ID
, ::sal_Int16(0));
250 const css::uno::Reference
< css::ui::dialogs::XFilePickerListener
> xListener
= rRequest
->getArgumentOrDefault(PROP_PICKER_LISTENER
, css::uno::Reference
< css::ui::dialogs::XFilePickerListener
>());
252 if ( ! xListener
.is())
255 css::ui::dialogs::FilePickerEvent aEvent
;
256 aEvent
.ElementId
= nControlID
;
260 case VistaFilePickerEventHandler::E_FILE_SELECTION_CHANGED
:
261 xListener
->fileSelectionChanged(aEvent
);
264 case VistaFilePickerEventHandler::E_DIRECTORY_CHANGED
:
265 xListener
->directoryChanged(aEvent
);
268 case VistaFilePickerEventHandler::E_HELP_REQUESTED
:
269 xListener
->helpRequested(aEvent
);
272 case VistaFilePickerEventHandler::E_CONTROL_STATE_CHANGED
:
273 xListener
->controlStateChanged(aEvent
);
276 case VistaFilePickerEventHandler::E_DIALOG_SIZE_CHANGED
:
277 xListener
->dialogSizeChanged();
280 // no default here. Let compiler detect changes on enum set !
284 virtual void after() override
289 void VistaFilePickerEventHandler::impl_sendEvent( EEventType eEventType
,
290 ::sal_Int16 nControlID
)
292 // See special handling in ~AsyncRequests for this static
293 static AsyncRequests
aNotify(RequestHandlerRef(new AsyncPickerEvents()));
295 ::cppu::OInterfaceContainerHelper
* pContainer
= m_lListener
.getContainer( cppu::UnoType
<css::ui::dialogs::XFilePickerListener
>::get());
299 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
300 while (pIterator
.hasMoreElements())
304 css::uno::Reference
< css::ui::dialogs::XFilePickerListener
> xListener (pIterator
.next(), css::uno::UNO_QUERY
);
306 RequestRef
rRequest(new Request());
307 rRequest
->setRequest (eEventType
);
308 rRequest
->setArgument(PROP_PICKER_LISTENER
, xListener
);
310 rRequest
->setArgument(PROP_CONTROL_ID
, nControlID
);
312 aNotify
.triggerRequestDirectly(rRequest
);
313 //aNotify.triggerRequestNonBlocked(rRequest);
315 catch(const css::uno::RuntimeException
&)
324 } // namespace fpicker
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */