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