LibreOffice Module fpicker (master) 1
VistaFilePickerEventHandler.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
23
24#include "requests.hxx"
25
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>
32
33#include <osl/file.hxx>
34
35
36// namespace directives
37
38
39namespace fpicker{
40namespace win32{
41namespace vista{
42
43
45 : m_nRefCount (0 )
46 , m_nListenerHandle (0 )
47 , m_pDialog ( )
48 , m_pInternalNotify (pInternalNotify)
49 , m_lListener (m_aMutex)
50{
51}
52
53
55{
56}
57
58
59HRESULT STDMETHODCALLTYPE VistaFilePickerEventHandler::QueryInterface(REFIID rIID ,
60 void** ppObject)
61{
62 *ppObject=nullptr;
63
64 if ( rIID == IID_IUnknown )
65 *ppObject = static_cast<IUnknown*>(static_cast<IFileDialogEvents*>(this));
66
67 if ( rIID == IID_IFileDialogEvents )
68 *ppObject = static_cast<IFileDialogEvents*>(this);
69
70 if ( rIID == IID_IFileDialogControlEvents )
71 *ppObject = static_cast<IFileDialogControlEvents*>(this);
72
73 if ( *ppObject != nullptr )
74 {
75 static_cast<IUnknown*>(*ppObject)->AddRef();
76 return S_OK;
77 }
78
79 return E_NOINTERFACE;
80}
81
82
83ULONG STDMETHODCALLTYPE VistaFilePickerEventHandler::AddRef()
84{
85 return osl_atomic_increment(&m_nRefCount);
86}
87
88
89ULONG STDMETHODCALLTYPE VistaFilePickerEventHandler::Release()
90{
91 ULONG nReturn = --m_nRefCount;
92 if ( m_nRefCount == 0 )
93 delete this;
94
95 return nReturn;
96}
97
98
99STDMETHODIMP VistaFilePickerEventHandler::OnFileOk(IFileDialog* /*pDialog*/)
100{
101 return E_NOTIMPL;
102}
103
104
105STDMETHODIMP VistaFilePickerEventHandler::OnFolderChanging(IFileDialog* /*pDialog*/,
106 IShellItem* /*pFolder*/)
107{
108 return E_NOTIMPL;
109}
110
111
112STDMETHODIMP VistaFilePickerEventHandler::OnFolderChange(IFileDialog* /*pDialog*/)
113{
116 return S_OK;
117}
118
119
120STDMETHODIMP VistaFilePickerEventHandler::OnSelectionChange(IFileDialog* /*pDialog*/)
121{
123 return S_OK;
124}
125
126
127STDMETHODIMP VistaFilePickerEventHandler::OnShareViolation(IFileDialog* /*pDialog*/ ,
128
129 IShellItem* /*pItem*/ ,
130
131 FDE_SHAREVIOLATION_RESPONSE* /*pResponse*/)
132{
133 impl_sendEvent(E_CONTROL_STATE_CHANGED, css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER);
134 return S_OK;
135}
136
137
138STDMETHODIMP VistaFilePickerEventHandler::OnTypeChange(IFileDialog* pDialog)
139{
140 UINT nFileTypeIndex;
141 HRESULT hResult = pDialog->GetFileTypeIndex( &nFileTypeIndex );
142
143 if ( hResult == S_OK )
144 {
145 if ( m_pInternalNotify->onFileTypeChanged( nFileTypeIndex ))
146 impl_sendEvent(E_CONTROL_STATE_CHANGED, css::ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER);
147 }
148
149 return S_OK;
150}
151
152
153STDMETHODIMP VistaFilePickerEventHandler::OnOverwrite(IFileDialog* /*pDialog*/ ,
154 IShellItem* /*pItem*/ ,
155 FDE_OVERWRITE_RESPONSE* /*pResponse*/)
156{
157 return E_NOTIMPL;
158}
159
160
161STDMETHODIMP VistaFilePickerEventHandler::OnItemSelected(IFileDialogCustomize* /*pCustomize*/,
162
163 DWORD nIDCtl ,
164
165 DWORD /*nIDItem*/ )
166{
167
168 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl ));
169 return S_OK;
170}
171
172
173STDMETHODIMP VistaFilePickerEventHandler::OnButtonClicked(IFileDialogCustomize* /*pCustomize*/,
174 DWORD nIDCtl )
175{
176
177 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl));
178 return S_OK;
179}
180
181
182STDMETHODIMP VistaFilePickerEventHandler::OnCheckButtonToggled(IFileDialogCustomize* /*pCustomize*/,
183 DWORD nIDCtl ,
184 BOOL bChecked )
185{
186 if (nIDCtl == css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION)
188
189 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl));
190
191 return S_OK;
192}
193
194
195STDMETHODIMP VistaFilePickerEventHandler::OnControlActivating(IFileDialogCustomize* /*pCustomize*/,
196 DWORD nIDCtl )
197{
198 impl_sendEvent(E_CONTROL_STATE_CHANGED, static_cast<sal_Int16>( nIDCtl));
199 return S_OK;
200}
201
202
203void VistaFilePickerEventHandler::addFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener )
204{
206}
207
208
209void VistaFilePickerEventHandler::removeFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener )
210{
212}
213
214
216{
217 if (m_pDialog.is())
218 return;
219
220 m_pDialog = pBroadcaster;
221 m_pDialog->Advise(this, &m_nListenerHandle);
222}
223
224
226{
227 if (m_pDialog.is())
228 {
229 m_pDialog->Unadvise(m_nListenerHandle);
230 m_pDialog.clear();
231 }
232}
233
234const OUStringLiteral PROP_CONTROL_ID = u"control_id";
235const OUStringLiteral PROP_PICKER_LISTENER = u"picker_listener";
236
237namespace {
238
239void doRequest(Request& rRequest)
240{
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 >());
244
245 if ( ! xListener.is())
246 return;
247
248 css::ui::dialogs::FilePickerEvent aEvent;
249 aEvent.ElementId = nControlID;
250
251 switch (nEventID)
252 {
254 xListener->fileSelectionChanged(aEvent);
255 break;
256
258 xListener->directoryChanged(aEvent);
259 break;
260
262 xListener->helpRequested(aEvent);
263 break;
264
266 xListener->controlStateChanged(aEvent);
267 break;
268
270 xListener->dialogSizeChanged();
271 break;
272
273 // no default here. Let compiler detect changes on enum set !
274 }
275}
276
277}
278
280 ::sal_Int16 nControlID)
281{
283 if ( ! pContainer)
284 return;
285
286 comphelper::OInterfaceIteratorHelper2 pIterator(*pContainer);
287 while (pIterator.hasMoreElements())
288 {
289 try
290 {
291 css::uno::Reference< css::ui::dialogs::XFilePickerListener > xListener (
292 static_cast< css::ui::dialogs::XFilePickerListener* >(pIterator.next()));
293
294 Request rRequest;
295 rRequest.setRequest (eEventType);
296 rRequest.setArgument(PROP_PICKER_LISTENER, xListener);
297 if ( nControlID )
298 rRequest.setArgument(PROP_CONTROL_ID, nControlID);
299
300 doRequest(rRequest);
301 }
302 catch(const css::uno::RuntimeException&)
303 {
304 pIterator.remove();
305 }
306 }
307}
308
309} // namespace vista
310} // namespace win32
311} // namespace fpicker
312
313/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
css::uno::XInterface * next()
OInterfaceContainerHelper2 * getContainer(const css::uno::Type &rKey) const
sal_Int32 removeInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &r)
virtual bool onFileTypeChanged(UINT nTypeIndex)=0
virtual void onAutoExtensionChanged(bool bChecked)=0
void setArgument(const OUString &sName, const TArgumentType &aValue)
Definition: requests.hxx:52
void setRequest(::sal_Int32 nRequest)
Definition: requests.hxx:45
TArgumentType getArgumentOrDefault(const OUString &sName, const TArgumentType &aDefault)
Definition: requests.hxx:58
oslInterlockedCount m_nRefCount
ref count for AddRef/Release()
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID rIID, void **ppObject) override
virtual void addFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener > &xListener)
virtual ULONG STDMETHODCALLTYPE Release() override
void stopListening()
stop listening for file picker events on the internally cached dialog COM object.
STDMETHODIMP OnItemSelected(IFileDialogCustomize *pCustomize, DWORD nIDCtl, DWORD nIDItem) override
virtual void removeFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener > &xListener)
STDMETHODIMP OnFileOk(IFileDialog *pDialog) override
STDMETHODIMP OnFolderChanging(IFileDialog *pDialog, IShellItem *pFolder) override
comphelper::OMultiTypeInterfaceContainerHelper2 m_lListener
used to inform file picker listener asynchronously.
STDMETHODIMP OnControlActivating(IFileDialogCustomize *pCustomize, DWORD nIDCtl) override
STDMETHODIMP OnButtonClicked(IFileDialogCustomize *pCustomize, DWORD nIDCtl) override
void startListening(const TFileDialog &pBroadcaster)
start listening for file picker events on the given file open dialog COM object.
STDMETHODIMP OnSelectionChange(IFileDialog *pDialog) override
TFileDialog m_pDialog
cached file dialog instance (there we listen for events)
STDMETHODIMP OnCheckButtonToggled(IFileDialogCustomize *pCustomize, DWORD nIDCtl, BOOL bChecked) override
DWORD m_nListenerHandle
unique handle for this listener provided by the broadcaster on registration time
STDMETHODIMP OnTypeChange(IFileDialog *pDialog) override
VistaFilePickerEventHandler(IVistaFilePickerInternalNotify *pInternalNotify)
STDMETHODIMP OnFolderChange(IFileDialog *pDialog) override
STDMETHODIMP OnShareViolation(IFileDialog *pDialog, IShellItem *pItem, FDE_SHAREVIOLATION_RESPONSE *pResponse) override
void impl_sendEvent(EEventType eEventType, ::sal_Int16 nControlID)
STDMETHODIMP OnOverwrite(IFileDialog *pDialog, IShellItem *pItem, FDE_OVERWRITE_RESPONSE *pResponse) override
float u
std::mutex m_aMutex
const OUStringLiteral PROP_PICKER_LISTENER
sal::systools::COMReference< IFileDialog > TFileDialog
Definition: vistatypes.h:33
const OUStringLiteral PROP_CONTROL_ID
const wchar_t *typedef BOOL