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