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