1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: target.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
35 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #ifndef _CPPUHELPER_COMPBASE2_HXX_
39 #include <cppuhelper/compbase3.hxx>
41 #include <cppuhelper/interfacecontainer.hxx>
43 #include <osl/mutex.hxx>
47 #pragma warning(push,1)
53 #include "globals.hxx"
54 #include "../../inc/DtObjFactory.hxx"
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::datatransfer
;
63 using namespace ::com::sun::star::datatransfer::dnd
;
67 // has to call XComponent::dispose. The thread that calls initialize
68 // must also execute the destruction of the instance. This is because
69 // initialize calls OleInitialize and the destructor calls OleUninitialize.
70 // If the service calls OleInitialize then it also calls OleUnitialize when
71 // it is destroyed. Therefore no second instance may exist which was
72 // created in the same thread and still needs OLE.
73 class DropTarget
: public MutexDummy
,
74 public WeakComponentImplHelper3
< XInitialization
, XDropTarget
, XServiceInfo
>
78 friend DWORD WINAPI
DndTargetOleSTAFunc(LPVOID pParams
);
79 // The native window which acts as drop target.
80 // It is set in initialize. In case RegisterDragDrop fails it is set
82 HWND m_hWnd
; // set by initialize
83 // Holds the thread id of the thread which created the window that is the
84 // drop target. Only used when DropTarget::initialize is called from an MTA
86 DWORD m_threadIdWindow
;
87 // This is the thread id of the OLE thread that is created in DropTarget::initialize
88 // when the calling thread is an MTA
89 DWORD m_threadIdTarget
;
90 // The handle of the thread that is created in DropTarget::initialize
91 // when the calling thread is an MTA
93 // The thread id of the thread which called initialize. When the service dies
94 // than m_oleThreadId is used to determine if the service successfully called
95 // OleInitialize. If so then OleUninitialize has to be called.
97 // An Instance of IDropTargetImpl which receives calls from the system's drag
98 // and drop implementation. It delegate the calls to name alike functions in
100 IDropTarget
* m_pDropTarget
;
102 Reference
<XMultiServiceFactory
> m_serviceFactory
;
103 // If m_bActive == sal_True then events are fired to XDropTargetListener s,
104 // none otherwise. The default value is sal_True.
106 sal_Int8 m_nDefaultActions
;
108 // This value is set when a XDropTargetListener calls accept or reject on
109 // the XDropTargetDropContext or XDropTargetDragContext.
110 // The values are from the DNDConstants group.
111 sal_Int8 m_nCurrentDropAction
;
112 // This value is manipulated by the XDropTargetListener
113 sal_Int8 m_nLastDropAction
;
115 Reference
<XTransferable
> m_currentData
;
116 // The current action is used to determine if the USER
117 // action has changed (dropActionChanged)
118 // sal_Int8 m_userAction;
119 // Set by listeners when they call XDropTargetDropContext::dropComplete
120 sal_Bool m_bDropComplete
;
121 // converts IDataObject objects to XTransferable objects.
122 CDTransObjFactory m_aDataConverter
;
123 Reference
<XDropTargetDragContext
> m_currentDragContext
;
124 Reference
<XDropTargetDropContext
> m_currentDropContext
;
129 DropTarget(DropTarget
&);
130 DropTarget
&operator= (DropTarget
&);
133 DropTarget(const Reference
<XMultiServiceFactory
>& sf
);
134 virtual ~DropTarget();
136 // Overrides WeakComponentImplHelper::disposing which is called by
137 // WeakComponentImplHelper::dispose
139 virtual void SAL_CALL
disposing();
141 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
)
142 throw(Exception
, RuntimeException
);
145 virtual void SAL_CALL
addDropTargetListener( const Reference
< XDropTargetListener
>& dtl
)
146 throw(RuntimeException
);
147 virtual void SAL_CALL
removeDropTargetListener( const Reference
< XDropTargetListener
>& dtl
)
148 throw(RuntimeException
);
149 // Default is not active
150 virtual sal_Bool SAL_CALL
isActive( ) throw(RuntimeException
);
151 virtual void SAL_CALL
setActive( sal_Bool isActive
) throw(RuntimeException
);
152 virtual sal_Int8 SAL_CALL
getDefaultActions( ) throw(RuntimeException
);
153 virtual void SAL_CALL
setDefaultActions( sal_Int8 actions
) throw(RuntimeException
);
156 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
157 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (RuntimeException
);
158 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
161 // Functions called from the IDropTarget implementation ( m_pDropTarget)
162 virtual HRESULT
DragEnter(
163 /* [unique][in] */ IDataObject
*pDataObj
,
164 /* [in] */ DWORD grfKeyState
,
165 /* [in] */ POINTL pt
,
166 /* [out][in] */ DWORD
*pdwEffect
);
168 virtual HRESULT STDMETHODCALLTYPE
DragOver(
169 /* [in] */ DWORD grfKeyState
,
170 /* [in] */ POINTL pt
,
171 /* [out][in] */ DWORD
*pdwEffect
);
173 virtual HRESULT STDMETHODCALLTYPE
DragLeave( ) ;
175 virtual HRESULT STDMETHODCALLTYPE
Drop(
176 /* [unique][in] */ IDataObject
*pDataObj
,
177 /* [in] */ DWORD grfKeyState
,
178 /* [in] */ POINTL pt
,
179 /* [out][in] */ DWORD
*pdwEffect
);
182 // Non - interface functions --------------------------------------------------
183 // XDropTargetDropContext delegated from DropContext
185 void _acceptDrop( sal_Int8 dropOperation
, const Reference
<XDropTargetDropContext
>& context
);
186 void _rejectDrop( const Reference
<XDropTargetDropContext
>& context
);
187 void _dropComplete( sal_Bool success
, const Reference
<XDropTargetDropContext
>& context
);
189 // XDropTargetDragContext delegated from DragContext
190 void _acceptDrag( sal_Int8 dragOperation
, const Reference
<XDropTargetDragContext
>& context
);
191 void _rejectDrag( const Reference
<XDropTargetDragContext
>& context
);
195 // Gets the current action dependend on the pressed modifiers, the effects
196 // supported by the drop source (IDropSource) and the default actions of the
197 // drop target (XDropTarget, this class))
198 inline sal_Int8
getFilteredActions( DWORD grfKeyState
, DWORD sourceActions
);
199 // Only filters with the default actions
200 inline sal_Int8
getFilteredActions( DWORD grfKeyState
);
204 void fire_drop( const DropTargetDropEvent
& dte
);
205 void fire_dragEnter( const DropTargetDragEnterEvent
& dtde
);
206 void fire_dragExit( const DropTargetEvent
& dte
);
207 void fire_dragOver( const DropTargetDragEvent
& dtde
);
208 void fire_dropActionChanged( const DropTargetDragEvent
& dtde
);