tdf#164434 Correct SvgSymbolNode SVG import
[LibreOffice.git] / fpicker / source / win32 / VistaFilePickerEventHandler.cxx
blob7c21dcde0392de166a1335b4f3ab048b1cfd5ff3
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 .
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
39 namespace fpicker{
40 namespace win32{
41 namespace vista{
44 VistaFilePickerEventHandler::VistaFilePickerEventHandler(IVistaFilePickerInternalNotify* pInternalNotify)
45 : m_nRefCount (0 )
46 , m_nListenerHandle (0 )
47 , m_pDialog ( )
48 , m_pInternalNotify (pInternalNotify)
49 , m_lListener (m_aMutex)
54 VistaFilePickerEventHandler::~VistaFilePickerEventHandler()
59 HRESULT STDMETHODCALLTYPE VistaFilePickerEventHandler::QueryInterface(REFIID rIID ,
60 void** ppObject)
62 *ppObject=nullptr;
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();
76 return S_OK;
79 return E_NOINTERFACE;
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 )
93 delete this;
95 return nReturn;
99 STDMETHODIMP VistaFilePickerEventHandler::OnFileOk(IFileDialog* /*pDialog*/)
101 return E_NOTIMPL;
105 STDMETHODIMP VistaFilePickerEventHandler::OnFolderChanging(IFileDialog* /*pDialog*/,
106 IShellItem* /*pFolder*/)
108 return E_NOTIMPL;
112 STDMETHODIMP VistaFilePickerEventHandler::OnFolderChange(IFileDialog* /*pDialog*/)
114 impl_sendEvent(E_DIRECTORY_CHANGED, 0);
115 m_pInternalNotify->onDirectoryChanged();
116 return S_OK;
120 STDMETHODIMP VistaFilePickerEventHandler::OnSelectionChange(IFileDialog* /*pDialog*/)
122 impl_sendEvent(E_FILE_SELECTION_CHANGED, 0);
123 return S_OK;
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);
134 return S_OK;
138 STDMETHODIMP VistaFilePickerEventHandler::OnTypeChange(IFileDialog* pDialog)
140 UINT nFileTypeIndex;
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);
149 return S_OK;
153 STDMETHODIMP VistaFilePickerEventHandler::OnOverwrite(IFileDialog* /*pDialog*/ ,
154 IShellItem* /*pItem*/ ,
155 FDE_OVERWRITE_RESPONSE* /*pResponse*/)
157 return E_NOTIMPL;
161 STDMETHODIMP VistaFilePickerEventHandler::OnItemSelected(IFileDialogCustomize* /*pCustomize*/,
163 DWORD nIDCtl ,
165 DWORD /*nIDItem*/ )
168 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl ));
169 return S_OK;
173 STDMETHODIMP VistaFilePickerEventHandler::OnButtonClicked(IFileDialogCustomize* /*pCustomize*/,
174 DWORD nIDCtl )
177 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl));
178 return S_OK;
182 STDMETHODIMP VistaFilePickerEventHandler::OnCheckButtonToggled(IFileDialogCustomize* /*pCustomize*/,
183 DWORD nIDCtl ,
184 BOOL bChecked )
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));
191 return S_OK;
195 STDMETHODIMP VistaFilePickerEventHandler::OnControlActivating(IFileDialogCustomize* /*pCustomize*/,
196 DWORD nIDCtl )
198 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl));
199 return S_OK;
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 )
217 if (m_pDialog.is())
218 return;
220 m_pDialog = pBroadcaster;
221 m_pDialog->Advise(this, &m_nListenerHandle);
225 void VistaFilePickerEventHandler::stopListening()
227 if (m_pDialog.is())
229 m_pDialog->Unadvise(m_nListenerHandle);
230 m_pDialog.clear();
234 constexpr OUString PROP_CONTROL_ID = u"control_id"_ustr;
235 constexpr OUString PROP_PICKER_LISTENER = u"picker_listener"_ustr;
237 namespace {
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())
246 return;
248 css::ui::dialogs::FilePickerEvent aEvent;
249 aEvent.ElementId = nControlID;
251 switch (nEventID)
253 case VistaFilePickerEventHandler::E_FILE_SELECTION_CHANGED :
254 xListener->fileSelectionChanged(aEvent);
255 break;
257 case VistaFilePickerEventHandler::E_DIRECTORY_CHANGED :
258 xListener->directoryChanged(aEvent);
259 break;
261 case VistaFilePickerEventHandler::E_HELP_REQUESTED :
262 xListener->helpRequested(aEvent);
263 break;
265 case VistaFilePickerEventHandler::E_CONTROL_STATE_CHANGED :
266 xListener->controlStateChanged(aEvent);
267 break;
269 case VistaFilePickerEventHandler::E_DIALOG_SIZE_CHANGED :
270 xListener->dialogSizeChanged();
271 break;
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());
283 if ( ! pContainer)
284 return;
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()));
294 Request rRequest;
295 rRequest.setRequest (eEventType);
296 rRequest.setArgument(PROP_PICKER_LISTENER, xListener);
297 if ( nControlID )
298 rRequest.setArgument(PROP_CONTROL_ID, nControlID);
300 doRequest(rRequest);
302 catch(const css::uno::RuntimeException&)
304 pIterator.remove();
309 } // namespace vista
310 } // namespace win32
311 } // namespace fpicker
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */