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