Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / fpicker / source / win32 / VistaFilePickerEventHandler.cxx
blobe770bef25406b9920daace9f8eef3b1cbd13409f
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 .
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
38 namespace fpicker{
39 namespace win32{
40 namespace vista{
43 VistaFilePickerEventHandler::VistaFilePickerEventHandler(IVistaFilePickerInternalNotify* pInternalNotify)
44 : m_nRefCount (0 )
45 , m_nListenerHandle (0 )
46 , m_pDialog ( )
47 , m_pInternalNotify (pInternalNotify)
48 , m_lListener (m_aMutex)
53 VistaFilePickerEventHandler::~VistaFilePickerEventHandler()
58 HRESULT STDMETHODCALLTYPE VistaFilePickerEventHandler::QueryInterface(REFIID rIID ,
59 void** ppObject)
61 *ppObject=nullptr;
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();
75 return S_OK;
78 return E_NOINTERFACE;
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 )
92 delete this;
94 return nReturn;
98 STDMETHODIMP VistaFilePickerEventHandler::OnFileOk(IFileDialog* /*pDialog*/)
100 return E_NOTIMPL;
104 STDMETHODIMP VistaFilePickerEventHandler::OnFolderChanging(IFileDialog* /*pDialog*/,
105 IShellItem* /*pFolder*/)
107 return E_NOTIMPL;
111 STDMETHODIMP VistaFilePickerEventHandler::OnFolderChange(IFileDialog* /*pDialog*/)
113 impl_sendEvent(E_DIRECTORY_CHANGED, 0);
114 return S_OK;
118 STDMETHODIMP VistaFilePickerEventHandler::OnSelectionChange(IFileDialog* /*pDialog*/)
120 impl_sendEvent(E_FILE_SELECTION_CHANGED, 0);
121 return S_OK;
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);
132 return S_OK;
136 STDMETHODIMP VistaFilePickerEventHandler::OnTypeChange(IFileDialog* pDialog)
138 UINT nFileTypeIndex;
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);
147 return S_OK;
151 STDMETHODIMP VistaFilePickerEventHandler::OnOverwrite(IFileDialog* /*pDialog*/ ,
152 IShellItem* /*pItem*/ ,
153 FDE_OVERWRITE_RESPONSE* /*pResponse*/)
155 return E_NOTIMPL;
159 STDMETHODIMP VistaFilePickerEventHandler::OnItemSelected(IFileDialogCustomize* /*pCustomize*/,
161 DWORD nIDCtl ,
163 DWORD /*nIDItem*/ )
166 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl ));
167 return S_OK;
171 STDMETHODIMP VistaFilePickerEventHandler::OnButtonClicked(IFileDialogCustomize* /*pCustomize*/,
172 DWORD nIDCtl )
175 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl));
176 return S_OK;
180 STDMETHODIMP VistaFilePickerEventHandler::OnCheckButtonToggled(IFileDialogCustomize* /*pCustomize*/,
181 DWORD nIDCtl ,
182 BOOL bChecked )
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));
189 return S_OK;
193 STDMETHODIMP VistaFilePickerEventHandler::OnControlActivating(IFileDialogCustomize* /*pCustomize*/,
194 DWORD nIDCtl )
196 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl));
197 return S_OK;
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 )
215 if (m_pDialog.is())
216 return;
218 m_pDialog = pBroadcaster;
219 m_pDialog->Advise(this, &m_nListenerHandle);
223 void VistaFilePickerEventHandler::stopListening()
225 if (m_pDialog.is())
227 m_pDialog->Unadvise(m_nListenerHandle);
228 m_pDialog.release();
232 static const char PROP_CONTROL_ID[] = "control_id";
233 static const char PROP_PICKER_LISTENER[] = "picker_listener";
236 class AsyncPickerEvents : public RequestHandler
238 public:
240 AsyncPickerEvents()
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())
253 return;
255 css::ui::dialogs::FilePickerEvent aEvent;
256 aEvent.ElementId = nControlID;
258 switch (nEventID)
260 case VistaFilePickerEventHandler::E_FILE_SELECTION_CHANGED :
261 xListener->fileSelectionChanged(aEvent);
262 break;
264 case VistaFilePickerEventHandler::E_DIRECTORY_CHANGED :
265 xListener->directoryChanged(aEvent);
266 break;
268 case VistaFilePickerEventHandler::E_HELP_REQUESTED :
269 xListener->helpRequested(aEvent);
270 break;
272 case VistaFilePickerEventHandler::E_CONTROL_STATE_CHANGED :
273 xListener->controlStateChanged(aEvent);
274 break;
276 case VistaFilePickerEventHandler::E_DIALOG_SIZE_CHANGED :
277 xListener->dialogSizeChanged();
278 break;
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());
296 if ( ! pContainer)
297 return;
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);
309 if ( nControlID )
310 rRequest->setArgument(PROP_CONTROL_ID, nControlID);
312 aNotify.triggerRequestDirectly(rRequest);
313 //aNotify.triggerRequestNonBlocked(rRequest);
315 catch(const css::uno::RuntimeException&)
317 pIterator.remove();
322 } // namespace vista
323 } // namespace win32
324 } // namespace fpicker
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */