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