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 #ifndef _TARGET_HXX_ 28*cdf0e10cSrcweir #define _TARGET_HXX_ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #ifndef _CPPUHELPER_COMPBASE2_HXX_ 36*cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx> 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 39*cdf0e10cSrcweir #ifndef _OSL_MUTEX_H_ 40*cdf0e10cSrcweir #include <osl/mutex.hxx> 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #if defined _MSC_VER 44*cdf0e10cSrcweir #pragma warning(push,1) 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #include <oleidl.h> 47*cdf0e10cSrcweir #if defined _MSC_VER 48*cdf0e10cSrcweir #pragma warning(pop) 49*cdf0e10cSrcweir #endif 50*cdf0e10cSrcweir #include "globals.hxx" 51*cdf0e10cSrcweir #include "../../inc/DtObjFactory.hxx" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 55*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 56*cdf0e10cSrcweir using namespace cppu; 57*cdf0e10cSrcweir using namespace osl; 58*cdf0e10cSrcweir using namespace rtl; 59*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer; 60*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::dnd; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // The client 64*cdf0e10cSrcweir // has to call XComponent::dispose. The thread that calls initialize 65*cdf0e10cSrcweir // must also execute the destruction of the instance. This is because 66*cdf0e10cSrcweir // initialize calls OleInitialize and the destructor calls OleUninitialize. 67*cdf0e10cSrcweir // If the service calls OleInitialize then it also calls OleUnitialize when 68*cdf0e10cSrcweir // it is destroyed. Therefore no second instance may exist which was 69*cdf0e10cSrcweir // created in the same thread and still needs OLE. 70*cdf0e10cSrcweir class DropTarget: public MutexDummy, 71*cdf0e10cSrcweir public WeakComponentImplHelper3< XInitialization, XDropTarget, XServiceInfo> 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir private: 75*cdf0e10cSrcweir friend DWORD WINAPI DndTargetOleSTAFunc(LPVOID pParams); 76*cdf0e10cSrcweir // The native window which acts as drop target. 77*cdf0e10cSrcweir // It is set in initialize. In case RegisterDragDrop fails it is set 78*cdf0e10cSrcweir // to NULL 79*cdf0e10cSrcweir HWND m_hWnd; // set by initialize 80*cdf0e10cSrcweir // Holds the thread id of the thread which created the window that is the 81*cdf0e10cSrcweir // drop target. Only used when DropTarget::initialize is called from an MTA 82*cdf0e10cSrcweir // thread 83*cdf0e10cSrcweir DWORD m_threadIdWindow; 84*cdf0e10cSrcweir // This is the thread id of the OLE thread that is created in DropTarget::initialize 85*cdf0e10cSrcweir // when the calling thread is an MTA 86*cdf0e10cSrcweir DWORD m_threadIdTarget; 87*cdf0e10cSrcweir // The handle of the thread that is created in DropTarget::initialize 88*cdf0e10cSrcweir // when the calling thread is an MTA 89*cdf0e10cSrcweir HANDLE m_hOleThread; 90*cdf0e10cSrcweir // The thread id of the thread which called initialize. When the service dies 91*cdf0e10cSrcweir // than m_oleThreadId is used to determine if the service successfully called 92*cdf0e10cSrcweir // OleInitialize. If so then OleUninitialize has to be called. 93*cdf0e10cSrcweir DWORD m_oleThreadId; 94*cdf0e10cSrcweir // An Instance of IDropTargetImpl which receives calls from the system's drag 95*cdf0e10cSrcweir // and drop implementation. It delegate the calls to name alike functions in 96*cdf0e10cSrcweir // this class. 97*cdf0e10cSrcweir IDropTarget* m_pDropTarget; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir Reference<XMultiServiceFactory> m_serviceFactory; 100*cdf0e10cSrcweir // If m_bActive == sal_True then events are fired to XDropTargetListener s, 101*cdf0e10cSrcweir // none otherwise. The default value is sal_True. 102*cdf0e10cSrcweir sal_Bool m_bActive; 103*cdf0e10cSrcweir sal_Int8 m_nDefaultActions; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // This value is set when a XDropTargetListener calls accept or reject on 106*cdf0e10cSrcweir // the XDropTargetDropContext or XDropTargetDragContext. 107*cdf0e10cSrcweir // The values are from the DNDConstants group. 108*cdf0e10cSrcweir sal_Int8 m_nCurrentDropAction; 109*cdf0e10cSrcweir // This value is manipulated by the XDropTargetListener 110*cdf0e10cSrcweir sal_Int8 m_nLastDropAction; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir Reference<XTransferable> m_currentData; 113*cdf0e10cSrcweir // The current action is used to determine if the USER 114*cdf0e10cSrcweir // action has changed (dropActionChanged) 115*cdf0e10cSrcweir // sal_Int8 m_userAction; 116*cdf0e10cSrcweir // Set by listeners when they call XDropTargetDropContext::dropComplete 117*cdf0e10cSrcweir sal_Bool m_bDropComplete; 118*cdf0e10cSrcweir // converts IDataObject objects to XTransferable objects. 119*cdf0e10cSrcweir CDTransObjFactory m_aDataConverter; 120*cdf0e10cSrcweir Reference<XDropTargetDragContext> m_currentDragContext; 121*cdf0e10cSrcweir Reference<XDropTargetDropContext> m_currentDropContext; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir private: 125*cdf0e10cSrcweir DropTarget(); 126*cdf0e10cSrcweir DropTarget(DropTarget&); 127*cdf0e10cSrcweir DropTarget &operator= (DropTarget&); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir public: 130*cdf0e10cSrcweir DropTarget(const Reference<XMultiServiceFactory>& sf); 131*cdf0e10cSrcweir virtual ~DropTarget(); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // Overrides WeakComponentImplHelper::disposing which is called by 134*cdf0e10cSrcweir // WeakComponentImplHelper::dispose 135*cdf0e10cSrcweir // Must be called. 136*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 137*cdf0e10cSrcweir // XInitialization 138*cdf0e10cSrcweir virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) 139*cdf0e10cSrcweir throw(Exception, RuntimeException); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // XDropTarget 142*cdf0e10cSrcweir virtual void SAL_CALL addDropTargetListener( const Reference< XDropTargetListener >& dtl ) 143*cdf0e10cSrcweir throw(RuntimeException); 144*cdf0e10cSrcweir virtual void SAL_CALL removeDropTargetListener( const Reference< XDropTargetListener >& dtl ) 145*cdf0e10cSrcweir throw(RuntimeException); 146*cdf0e10cSrcweir // Default is not active 147*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isActive( ) throw(RuntimeException); 148*cdf0e10cSrcweir virtual void SAL_CALL setActive( sal_Bool isActive ) throw(RuntimeException); 149*cdf0e10cSrcweir virtual sal_Int8 SAL_CALL getDefaultActions( ) throw(RuntimeException); 150*cdf0e10cSrcweir virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) throw(RuntimeException); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // XServiceInfo 153*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException); 154*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException); 155*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // Functions called from the IDropTarget implementation ( m_pDropTarget) 159*cdf0e10cSrcweir virtual HRESULT DragEnter( 160*cdf0e10cSrcweir /* [unique][in] */ IDataObject *pDataObj, 161*cdf0e10cSrcweir /* [in] */ DWORD grfKeyState, 162*cdf0e10cSrcweir /* [in] */ POINTL pt, 163*cdf0e10cSrcweir /* [out][in] */ DWORD *pdwEffect); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE DragOver( 166*cdf0e10cSrcweir /* [in] */ DWORD grfKeyState, 167*cdf0e10cSrcweir /* [in] */ POINTL pt, 168*cdf0e10cSrcweir /* [out][in] */ DWORD *pdwEffect); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE DragLeave( ) ; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE Drop( 173*cdf0e10cSrcweir /* [unique][in] */ IDataObject *pDataObj, 174*cdf0e10cSrcweir /* [in] */ DWORD grfKeyState, 175*cdf0e10cSrcweir /* [in] */ POINTL pt, 176*cdf0e10cSrcweir /* [out][in] */ DWORD *pdwEffect); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // Non - interface functions -------------------------------------------------- 180*cdf0e10cSrcweir // XDropTargetDropContext delegated from DropContext 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir void _acceptDrop( sal_Int8 dropOperation, const Reference<XDropTargetDropContext>& context); 183*cdf0e10cSrcweir void _rejectDrop( const Reference<XDropTargetDropContext>& context); 184*cdf0e10cSrcweir void _dropComplete( sal_Bool success, const Reference<XDropTargetDropContext>& context); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // XDropTargetDragContext delegated from DragContext 187*cdf0e10cSrcweir void _acceptDrag( sal_Int8 dragOperation, const Reference<XDropTargetDragContext>& context); 188*cdf0e10cSrcweir void _rejectDrag( const Reference<XDropTargetDragContext>& context); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir protected: 192*cdf0e10cSrcweir // Gets the current action dependend on the pressed modifiers, the effects 193*cdf0e10cSrcweir // supported by the drop source (IDropSource) and the default actions of the 194*cdf0e10cSrcweir // drop target (XDropTarget, this class)) 195*cdf0e10cSrcweir inline sal_Int8 getFilteredActions( DWORD grfKeyState, DWORD sourceActions); 196*cdf0e10cSrcweir // Only filters with the default actions 197*cdf0e10cSrcweir inline sal_Int8 getFilteredActions( DWORD grfKeyState); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir void fire_drop( const DropTargetDropEvent& dte); 202*cdf0e10cSrcweir void fire_dragEnter( const DropTargetDragEnterEvent& dtde ); 203*cdf0e10cSrcweir void fire_dragExit( const DropTargetEvent& dte ); 204*cdf0e10cSrcweir void fire_dragOver( const DropTargetDragEvent& dtde ); 205*cdf0e10cSrcweir void fire_dropActionChanged( const DropTargetDragEvent& dtde ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir }; 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir #endif 214