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