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