1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef FPICKER_WIN32_VISTA_FILEPICKER_EVENTHANDLER_HXX 29*cdf0e10cSrcweir #define FPICKER_WIN32_VISTA_FILEPICKER_EVENTHANDLER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //----------------------------------------------------------------------------- 32*cdf0e10cSrcweir // includes 33*cdf0e10cSrcweir //----------------------------------------------------------------------------- 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #if defined(_MSC_VER) && (_MSC_VER >= 1400) 36*cdf0e10cSrcweir #pragma warning( disable : 4917 ) 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include "comptr.hxx" 40*cdf0e10cSrcweir #include "vistatypes.h" 41*cdf0e10cSrcweir #include "IVistaFilePickerInternalNotify.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 47*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h> 48*cdf0e10cSrcweir #include <osl/interlck.h> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include <shobjidl.h> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //----------------------------------------------------------------------------- 53*cdf0e10cSrcweir // namespace 54*cdf0e10cSrcweir //----------------------------------------------------------------------------- 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #ifdef css 57*cdf0e10cSrcweir #error "Clash on using CSS as namespace define." 58*cdf0e10cSrcweir #else 59*cdf0e10cSrcweir #define css ::com::sun::star 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir namespace fpicker{ 63*cdf0e10cSrcweir namespace win32{ 64*cdf0e10cSrcweir namespace vista{ 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //----------------------------------------------------------------------------- 67*cdf0e10cSrcweir // types, const etcpp. 68*cdf0e10cSrcweir //----------------------------------------------------------------------------- 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //----------------------------------------------------------------------------- 71*cdf0e10cSrcweir /** todo document me 72*cdf0e10cSrcweir */ 73*cdf0e10cSrcweir class VistaFilePickerEventHandler : public ::cppu::BaseMutex 74*cdf0e10cSrcweir , public IFileDialogEvents 75*cdf0e10cSrcweir , public IFileDialogControlEvents 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir public: 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 80*cdf0e10cSrcweir // ctor/dtor 81*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir VistaFilePickerEventHandler(IVistaFilePickerInternalNotify* pInternalNotify); 84*cdf0e10cSrcweir virtual ~VistaFilePickerEventHandler(); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 87*cdf0e10cSrcweir // IUnknown 88*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 89*cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID rIID , 90*cdf0e10cSrcweir void** ppObject); 91*cdf0e10cSrcweir virtual ULONG STDMETHODCALLTYPE AddRef(); 92*cdf0e10cSrcweir virtual ULONG STDMETHODCALLTYPE Release(); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 95*cdf0e10cSrcweir // IFileDialogEvents 96*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir STDMETHODIMP OnFileOk(IFileDialog* pDialog); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir STDMETHODIMP OnFolderChanging(IFileDialog* pDialog, 101*cdf0e10cSrcweir IShellItem* pFolder); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir STDMETHODIMP OnFolderChange(IFileDialog* pDialog); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir STDMETHODIMP OnSelectionChange(IFileDialog* pDialog); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir STDMETHODIMP OnShareViolation(IFileDialog* pDialog , 108*cdf0e10cSrcweir IShellItem* pItem , 109*cdf0e10cSrcweir FDE_SHAREVIOLATION_RESPONSE* pResponse); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir STDMETHODIMP OnTypeChange(IFileDialog* pDialog); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir STDMETHODIMP OnOverwrite(IFileDialog* pDialog , 114*cdf0e10cSrcweir IShellItem* pItem , 115*cdf0e10cSrcweir FDE_OVERWRITE_RESPONSE* pResponse); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 118*cdf0e10cSrcweir // IFileDialogControlEvents 119*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir STDMETHODIMP OnItemSelected(IFileDialogCustomize* pCustomize, 122*cdf0e10cSrcweir DWORD nIDCtl , 123*cdf0e10cSrcweir DWORD nIDItem ); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir STDMETHODIMP OnButtonClicked(IFileDialogCustomize* pCustomize, 126*cdf0e10cSrcweir DWORD nIDCtl ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir STDMETHODIMP OnCheckButtonToggled(IFileDialogCustomize* pCustomize, 129*cdf0e10cSrcweir DWORD nIDCtl , 130*cdf0e10cSrcweir BOOL bChecked ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir STDMETHODIMP OnControlActivating(IFileDialogCustomize* pCustomize, 133*cdf0e10cSrcweir DWORD nIDCtl ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 136*cdf0e10cSrcweir // XFilePickerNotifier 137*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir virtual void SAL_CALL addFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) 140*cdf0e10cSrcweir throw( css::uno::RuntimeException ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir virtual void SAL_CALL removeFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) 143*cdf0e10cSrcweir throw( css::uno::RuntimeException ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 146*cdf0e10cSrcweir // native interface 147*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 150*cdf0e10cSrcweir /** start listening for file picker events on the given file open dialog COM object. 151*cdf0e10cSrcweir * 152*cdf0e10cSrcweir * The broadcaster will be cached internaly so deregistration will be easy. 153*cdf0e10cSrcweir * Further all needed informations are capsulated within this class (e.g. the listener handler). 154*cdf0e10cSrcweir * Nobody outside must know such informations. 155*cdf0e10cSrcweir * 156*cdf0e10cSrcweir * Nothing will happen if an inconsistent state will be detected 157*cdf0e10cSrcweir * (means: double registration will be ignored). 158*cdf0e10cSrcweir * 159*cdf0e10cSrcweir * @param pBroadcaster 160*cdf0e10cSrcweir * reference to the dialog, where we should start listening. 161*cdf0e10cSrcweir */ 162*cdf0e10cSrcweir void startListening( const TFileDialog& pBroadcaster ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 165*cdf0e10cSrcweir /** stop listening for file picker events on the internaly cached dialog COM object. 166*cdf0e10cSrcweir * 167*cdf0e10cSrcweir * The COM dialog provided on the startListeneing() call was cached internaly. 168*cdf0e10cSrcweir * And now its used to deregister this listener. Doing so the also internaly cached 169*cdf0e10cSrcweir * listener handle is used. If listener was not already registered - nothing will happen. 170*cdf0e10cSrcweir */ 171*cdf0e10cSrcweir void stopListening(); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir public: 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir enum EEventType 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir E_FILE_SELECTION_CHANGED, 178*cdf0e10cSrcweir E_DIRECTORY_CHANGED, 179*cdf0e10cSrcweir E_HELP_REQUESTED, 180*cdf0e10cSrcweir E_CONTROL_STATE_CHANGED, 181*cdf0e10cSrcweir E_DIALOG_SIZE_CHANGED 182*cdf0e10cSrcweir }; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir private: 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 187*cdf0e10cSrcweir /// @todo document me 188*cdf0e10cSrcweir void impl_sendEvent( EEventType eEventType, 189*cdf0e10cSrcweir ::sal_Int16 nControlID); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir private: 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 194*cdf0e10cSrcweir /// ref count for AddRef/Release() 195*cdf0e10cSrcweir oslInterlockedCount m_nRefCount; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 198*cdf0e10cSrcweir /// unique handle for this listener provided by the broadcaster on registration time 199*cdf0e10cSrcweir DWORD m_nListenerHandle; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 202*cdf0e10cSrcweir /// cached file dialog instance (there we listen for events) 203*cdf0e10cSrcweir TFileDialog m_pDialog; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir //--------------------------------------------------------------------- 206*cdf0e10cSrcweir IVistaFilePickerInternalNotify* m_pInternalNotify; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir //--------------------------------------------------------------------- 209*cdf0e10cSrcweir /** used to inform file picker listener asynchronously. 210*cdf0e10cSrcweir * Those listener must be called asynchronously .. because 211*cdf0e10cSrcweir * every request will block the caller thread. Mostly that will be 212*cdf0e10cSrcweir * the main thread of the office. Further the global SolarMutex will 213*cdf0e10cSrcweir * be locked during this time. If we call our listener back now synchronously .. 214*cdf0e10cSrcweir * we will block on SolarMutex.acquire() forever .-)) 215*cdf0e10cSrcweir */ 216*cdf0e10cSrcweir ::cppu::OMultiTypeInterfaceContainerHelper m_lListener; 217*cdf0e10cSrcweir }; 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir } // namespace vista 220*cdf0e10cSrcweir } // namespace win32 221*cdf0e10cSrcweir } // namespace fpicker 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir #undef css 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir #endif // FPICKER_WIN32_VISTA_FILEPICKER_EVENTHANDLER_HXX 226