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
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_dtrans.hxx"
26*b1cdbd2cSJim Jagielski #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
27*b1cdbd2cSJim Jagielski #include <com/sun/star/datatransfer/XTransferable.hpp>
28*b1cdbd2cSJim Jagielski #include <com/sun/star/awt/MouseButton.hpp>
29*b1cdbd2cSJim Jagielski #include <com/sun/star/awt/MouseEvent.hpp>
30*b1cdbd2cSJim Jagielski #include <rtl/unload.h>
31*b1cdbd2cSJim Jagielski
32*b1cdbd2cSJim Jagielski #include <process.h>
33*b1cdbd2cSJim Jagielski #include <memory>
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim Jagielski #include "source.hxx"
36*b1cdbd2cSJim Jagielski #include "globals.hxx"
37*b1cdbd2cSJim Jagielski #include "sourcecontext.hxx"
38*b1cdbd2cSJim Jagielski #include "../../inc/DtObjFactory.hxx"
39*b1cdbd2cSJim Jagielski #include <rtl/ustring.h>
40*b1cdbd2cSJim Jagielski #include <process.h>
41*b1cdbd2cSJim Jagielski #include <winuser.h>
42*b1cdbd2cSJim Jagielski #include <stdio.h>
43*b1cdbd2cSJim Jagielski
44*b1cdbd2cSJim Jagielski #ifdef __MINGW32__
45*b1cdbd2cSJim Jagielski #define __uuidof(I) IID_##I
46*b1cdbd2cSJim Jagielski #endif
47*b1cdbd2cSJim Jagielski
48*b1cdbd2cSJim Jagielski using namespace rtl;
49*b1cdbd2cSJim Jagielski using namespace cppu;
50*b1cdbd2cSJim Jagielski using namespace osl;
51*b1cdbd2cSJim Jagielski using namespace com::sun::star::datatransfer;
52*b1cdbd2cSJim Jagielski using namespace com::sun::star::datatransfer::dnd;
53*b1cdbd2cSJim Jagielski using namespace com::sun::star::datatransfer::dnd::DNDConstants;
54*b1cdbd2cSJim Jagielski using namespace com::sun::star::uno;
55*b1cdbd2cSJim Jagielski using namespace com::sun::star::awt::MouseButton;
56*b1cdbd2cSJim Jagielski using namespace com::sun::star::awt;
57*b1cdbd2cSJim Jagielski using namespace com::sun::star::lang;
58*b1cdbd2cSJim Jagielski
59*b1cdbd2cSJim Jagielski extern rtl_StandardModuleCount g_moduleCount;
60*b1cdbd2cSJim Jagielski
61*b1cdbd2cSJim Jagielski //--> TRA
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski extern Reference< XTransferable > g_XTransferable;
64*b1cdbd2cSJim Jagielski
65*b1cdbd2cSJim Jagielski //<-- TRA
66*b1cdbd2cSJim Jagielski
67*b1cdbd2cSJim Jagielski unsigned __stdcall DndOleSTAFunc(LPVOID pParams);
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski //----------------------------------------------------
70*b1cdbd2cSJim Jagielski /** Ctor
71*b1cdbd2cSJim Jagielski */
DragSource(const Reference<XMultiServiceFactory> & sf)72*b1cdbd2cSJim Jagielski DragSource::DragSource( const Reference<XMultiServiceFactory>& sf):
73*b1cdbd2cSJim Jagielski m_serviceFactory( sf),
74*b1cdbd2cSJim Jagielski WeakComponentImplHelper3< XDragSource, XInitialization, XServiceInfo >(m_mutex),
75*b1cdbd2cSJim Jagielski // m_pcurrentContext_impl(0),
76*b1cdbd2cSJim Jagielski m_hAppWindow(0),
77*b1cdbd2cSJim Jagielski m_MouseButton(0),
78*b1cdbd2cSJim Jagielski m_RunningDndOperationCount(0)
79*b1cdbd2cSJim Jagielski {
80*b1cdbd2cSJim Jagielski g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
81*b1cdbd2cSJim Jagielski }
82*b1cdbd2cSJim Jagielski
83*b1cdbd2cSJim Jagielski //----------------------------------------------------
84*b1cdbd2cSJim Jagielski /** Dtor
85*b1cdbd2cSJim Jagielski */
~DragSource()86*b1cdbd2cSJim Jagielski DragSource::~DragSource()
87*b1cdbd2cSJim Jagielski {
88*b1cdbd2cSJim Jagielski g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
89*b1cdbd2cSJim Jagielski }
90*b1cdbd2cSJim Jagielski
91*b1cdbd2cSJim Jagielski //----------------------------------------------------
92*b1cdbd2cSJim Jagielski /** First start a new drag and drop thread if
93*b1cdbd2cSJim Jagielski the last one has finished
94*b1cdbd2cSJim Jagielski
95*b1cdbd2cSJim Jagielski ????
96*b1cdbd2cSJim Jagielski Do we really need a separate thread for
97*b1cdbd2cSJim Jagielski every Dnd opeartion or only if the source
98*b1cdbd2cSJim Jagielski thread is an MTA thread
99*b1cdbd2cSJim Jagielski ????
100*b1cdbd2cSJim Jagielski */
StartDragImpl(const DragGestureEvent & trigger,sal_Int8 sourceActions,sal_Int32,sal_Int32,const Reference<XTransferable> & trans,const Reference<XDragSourceListener> & listener)101*b1cdbd2cSJim Jagielski void DragSource::StartDragImpl(
102*b1cdbd2cSJim Jagielski const DragGestureEvent& trigger,
103*b1cdbd2cSJim Jagielski sal_Int8 sourceActions,
104*b1cdbd2cSJim Jagielski sal_Int32 /*cursor*/,
105*b1cdbd2cSJim Jagielski sal_Int32 /*image*/,
106*b1cdbd2cSJim Jagielski const Reference<XTransferable >& trans,
107*b1cdbd2cSJim Jagielski const Reference<XDragSourceListener >& listener )
108*b1cdbd2cSJim Jagielski {
109*b1cdbd2cSJim Jagielski // The actions supported by the drag source
110*b1cdbd2cSJim Jagielski m_sourceActions= sourceActions;
111*b1cdbd2cSJim Jagielski // We need to know which mouse button triggered the operation.
112*b1cdbd2cSJim Jagielski // If it was the left one, then the drop occurs when that button
113*b1cdbd2cSJim Jagielski // has been released and if it was the right one then the drop
114*b1cdbd2cSJim Jagielski // occurs when the right button has been released. If the event is not
115*b1cdbd2cSJim Jagielski // set then we assume that the left button is pressed.
116*b1cdbd2cSJim Jagielski MouseEvent evtMouse;
117*b1cdbd2cSJim Jagielski trigger.Event >>= evtMouse;
118*b1cdbd2cSJim Jagielski m_MouseButton= evtMouse.Buttons;
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim Jagielski // The SourceContext class administers the XDragSourceListener s and
121*b1cdbd2cSJim Jagielski // fires events to them. An instance only exists in the scope of this
122*b1cdbd2cSJim Jagielski // functions. However, the drag and drop operation causes callbacks
123*b1cdbd2cSJim Jagielski // to the IDropSource interface implemented in this class (but only
124*b1cdbd2cSJim Jagielski // while this function executes). The source context is also used
125*b1cdbd2cSJim Jagielski // in DragSource::QueryContinueDrag.
126*b1cdbd2cSJim Jagielski m_currentContext= static_cast<XDragSourceContext*>( new SourceContext(
127*b1cdbd2cSJim Jagielski static_cast<DragSource*>(this), listener ) );
128*b1cdbd2cSJim Jagielski
129*b1cdbd2cSJim Jagielski // Convert the XTransferable data object into an IDataObject object;
130*b1cdbd2cSJim Jagielski
131*b1cdbd2cSJim Jagielski //--> TRA
132*b1cdbd2cSJim Jagielski g_XTransferable = trans;
133*b1cdbd2cSJim Jagielski //<-- TRA
134*b1cdbd2cSJim Jagielski
135*b1cdbd2cSJim Jagielski m_spDataObject= m_aDataConverter.createDataObjFromTransferable(
136*b1cdbd2cSJim Jagielski m_serviceFactory, trans);
137*b1cdbd2cSJim Jagielski
138*b1cdbd2cSJim Jagielski // Obtain the id of the thread that created the window
139*b1cdbd2cSJim Jagielski DWORD processId;
140*b1cdbd2cSJim Jagielski m_threadIdWindow= GetWindowThreadProcessId( m_hAppWindow, &processId);
141*b1cdbd2cSJim Jagielski
142*b1cdbd2cSJim Jagielski // hold the instance for the DnD thread, it's to late
143*b1cdbd2cSJim Jagielski // to acquire at the start of the thread procedure
144*b1cdbd2cSJim Jagielski // the thread procedure is responsible for the release
145*b1cdbd2cSJim Jagielski acquire();
146*b1cdbd2cSJim Jagielski
147*b1cdbd2cSJim Jagielski // The thread acccesses members of this instance but does not call acquire.
148*b1cdbd2cSJim Jagielski // Hopefully this instance is not destroyed before the thread has terminated.
149*b1cdbd2cSJim Jagielski unsigned threadId;
150*b1cdbd2cSJim Jagielski HANDLE hThread= reinterpret_cast<HANDLE>(_beginthreadex(
151*b1cdbd2cSJim Jagielski 0, 0, DndOleSTAFunc, reinterpret_cast<void*>(this), 0, &threadId));
152*b1cdbd2cSJim Jagielski
153*b1cdbd2cSJim Jagielski // detach from thread
154*b1cdbd2cSJim Jagielski CloseHandle(hThread);
155*b1cdbd2cSJim Jagielski }
156*b1cdbd2cSJim Jagielski
157*b1cdbd2cSJim Jagielski // XInitialization
158*b1cdbd2cSJim Jagielski
159*b1cdbd2cSJim Jagielski //----------------------------------------------------
160*b1cdbd2cSJim Jagielski /** aArguments contains a machine id
161*b1cdbd2cSJim Jagielski */
initialize(const Sequence<Any> & aArguments)162*b1cdbd2cSJim Jagielski void SAL_CALL DragSource::initialize( const Sequence< Any >& aArguments )
163*b1cdbd2cSJim Jagielski throw(Exception, RuntimeException)
164*b1cdbd2cSJim Jagielski {
165*b1cdbd2cSJim Jagielski if( aArguments.getLength() >=2)
166*b1cdbd2cSJim Jagielski m_hAppWindow= *(HWND*)aArguments[1].getValue();
167*b1cdbd2cSJim Jagielski OSL_ASSERT( IsWindow( m_hAppWindow) );
168*b1cdbd2cSJim Jagielski }
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielski //----------------------------------------------------
171*b1cdbd2cSJim Jagielski /** XDragSource
172*b1cdbd2cSJim Jagielski */
isDragImageSupported()173*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL DragSource::isDragImageSupported( )
174*b1cdbd2cSJim Jagielski throw(RuntimeException)
175*b1cdbd2cSJim Jagielski {
176*b1cdbd2cSJim Jagielski return 0;
177*b1cdbd2cSJim Jagielski }
178*b1cdbd2cSJim Jagielski
179*b1cdbd2cSJim Jagielski //----------------------------------------------------
180*b1cdbd2cSJim Jagielski /**
181*b1cdbd2cSJim Jagielski */
getDefaultCursor(sal_Int8)182*b1cdbd2cSJim Jagielski sal_Int32 SAL_CALL DragSource::getDefaultCursor( sal_Int8 /*dragAction*/ )
183*b1cdbd2cSJim Jagielski throw( IllegalArgumentException, RuntimeException)
184*b1cdbd2cSJim Jagielski {
185*b1cdbd2cSJim Jagielski return 0;
186*b1cdbd2cSJim Jagielski }
187*b1cdbd2cSJim Jagielski
188*b1cdbd2cSJim Jagielski //----------------------------------------------------
189*b1cdbd2cSJim Jagielski /** Notifies the XDragSourceListener by
190*b1cdbd2cSJim Jagielski calling dragDropEnd
191*b1cdbd2cSJim Jagielski */
startDrag(const DragGestureEvent & trigger,sal_Int8 sourceActions,sal_Int32 cursor,sal_Int32 image,const Reference<XTransferable> & trans,const Reference<XDragSourceListener> & listener)192*b1cdbd2cSJim Jagielski void SAL_CALL DragSource::startDrag(
193*b1cdbd2cSJim Jagielski const DragGestureEvent& trigger,
194*b1cdbd2cSJim Jagielski sal_Int8 sourceActions,
195*b1cdbd2cSJim Jagielski sal_Int32 cursor,
196*b1cdbd2cSJim Jagielski sal_Int32 image,
197*b1cdbd2cSJim Jagielski const Reference<XTransferable >& trans,
198*b1cdbd2cSJim Jagielski const Reference<XDragSourceListener >& listener ) throw( RuntimeException)
199*b1cdbd2cSJim Jagielski {
200*b1cdbd2cSJim Jagielski // Allow only one running dnd operation at a time,
201*b1cdbd2cSJim Jagielski // see XDragSource documentation
202*b1cdbd2cSJim Jagielski
203*b1cdbd2cSJim Jagielski long cnt = InterlockedIncrement(&m_RunningDndOperationCount);
204*b1cdbd2cSJim Jagielski
205*b1cdbd2cSJim Jagielski if (1 == cnt)
206*b1cdbd2cSJim Jagielski {
207*b1cdbd2cSJim Jagielski StartDragImpl(trigger, sourceActions, cursor, image, trans, listener);
208*b1cdbd2cSJim Jagielski }
209*b1cdbd2cSJim Jagielski else
210*b1cdbd2cSJim Jagielski {
211*b1cdbd2cSJim Jagielski //OSL_ENSURE(false, "Overlapping Drag&Drop operation rejected!");
212*b1cdbd2cSJim Jagielski
213*b1cdbd2cSJim Jagielski cnt = InterlockedDecrement(&m_RunningDndOperationCount);
214*b1cdbd2cSJim Jagielski
215*b1cdbd2cSJim Jagielski DragSourceDropEvent dsde;
216*b1cdbd2cSJim Jagielski
217*b1cdbd2cSJim Jagielski dsde.DropAction = ACTION_NONE;
218*b1cdbd2cSJim Jagielski dsde.DropSuccess = false;
219*b1cdbd2cSJim Jagielski
220*b1cdbd2cSJim Jagielski try
221*b1cdbd2cSJim Jagielski {
222*b1cdbd2cSJim Jagielski listener->dragDropEnd(dsde);
223*b1cdbd2cSJim Jagielski }
224*b1cdbd2cSJim Jagielski catch(RuntimeException&)
225*b1cdbd2cSJim Jagielski {
226*b1cdbd2cSJim Jagielski OSL_ENSURE(false, "Runtime exception during event dispatching");
227*b1cdbd2cSJim Jagielski }
228*b1cdbd2cSJim Jagielski }
229*b1cdbd2cSJim Jagielski }
230*b1cdbd2cSJim Jagielski
231*b1cdbd2cSJim Jagielski //----------------------------------------------------
232*b1cdbd2cSJim Jagielski /**IDropTarget
233*b1cdbd2cSJim Jagielski */
QueryInterface(REFIID riid,void ** ppvObject)234*b1cdbd2cSJim Jagielski HRESULT STDMETHODCALLTYPE DragSource::QueryInterface( REFIID riid, void **ppvObject)
235*b1cdbd2cSJim Jagielski {
236*b1cdbd2cSJim Jagielski if( !ppvObject)
237*b1cdbd2cSJim Jagielski return E_POINTER;
238*b1cdbd2cSJim Jagielski *ppvObject= NULL;
239*b1cdbd2cSJim Jagielski
240*b1cdbd2cSJim Jagielski if( riid == __uuidof( IUnknown) )
241*b1cdbd2cSJim Jagielski *ppvObject= static_cast<IUnknown*>( this);
242*b1cdbd2cSJim Jagielski else if ( riid == __uuidof( IDropSource) )
243*b1cdbd2cSJim Jagielski *ppvObject= static_cast<IDropSource*>( this);
244*b1cdbd2cSJim Jagielski
245*b1cdbd2cSJim Jagielski if(*ppvObject)
246*b1cdbd2cSJim Jagielski {
247*b1cdbd2cSJim Jagielski AddRef();
248*b1cdbd2cSJim Jagielski return S_OK;
249*b1cdbd2cSJim Jagielski }
250*b1cdbd2cSJim Jagielski else
251*b1cdbd2cSJim Jagielski return E_NOINTERFACE;
252*b1cdbd2cSJim Jagielski
253*b1cdbd2cSJim Jagielski }
254*b1cdbd2cSJim Jagielski
255*b1cdbd2cSJim Jagielski //----------------------------------------------------
256*b1cdbd2cSJim Jagielski /**
257*b1cdbd2cSJim Jagielski */
AddRef(void)258*b1cdbd2cSJim Jagielski ULONG STDMETHODCALLTYPE DragSource::AddRef( void)
259*b1cdbd2cSJim Jagielski {
260*b1cdbd2cSJim Jagielski acquire();
261*b1cdbd2cSJim Jagielski return (ULONG) m_refCount;
262*b1cdbd2cSJim Jagielski }
263*b1cdbd2cSJim Jagielski
264*b1cdbd2cSJim Jagielski //----------------------------------------------------
265*b1cdbd2cSJim Jagielski /**
266*b1cdbd2cSJim Jagielski */
Release(void)267*b1cdbd2cSJim Jagielski ULONG STDMETHODCALLTYPE DragSource::Release( void)
268*b1cdbd2cSJim Jagielski {
269*b1cdbd2cSJim Jagielski ULONG ref= m_refCount;
270*b1cdbd2cSJim Jagielski release();
271*b1cdbd2cSJim Jagielski return --ref;
272*b1cdbd2cSJim Jagielski }
273*b1cdbd2cSJim Jagielski
274*b1cdbd2cSJim Jagielski //----------------------------------------------------
275*b1cdbd2cSJim Jagielski /** IDropSource
276*b1cdbd2cSJim Jagielski */
QueryContinueDrag(BOOL fEscapePressed,DWORD grfKeyState)277*b1cdbd2cSJim Jagielski HRESULT STDMETHODCALLTYPE DragSource::QueryContinueDrag(
278*b1cdbd2cSJim Jagielski /* [in] */ BOOL fEscapePressed,
279*b1cdbd2cSJim Jagielski /* [in] */ DWORD grfKeyState)
280*b1cdbd2cSJim Jagielski {
281*b1cdbd2cSJim Jagielski #if defined DBG_CONSOLE_OUT
282*b1cdbd2cSJim Jagielski printf("\nDragSource::QueryContinueDrag");
283*b1cdbd2cSJim Jagielski #endif
284*b1cdbd2cSJim Jagielski
285*b1cdbd2cSJim Jagielski HRESULT retVal= S_OK; // default continue DnD
286*b1cdbd2cSJim Jagielski
287*b1cdbd2cSJim Jagielski if (fEscapePressed)
288*b1cdbd2cSJim Jagielski {
289*b1cdbd2cSJim Jagielski retVal= DRAGDROP_S_CANCEL;
290*b1cdbd2cSJim Jagielski }
291*b1cdbd2cSJim Jagielski else
292*b1cdbd2cSJim Jagielski {
293*b1cdbd2cSJim Jagielski if( ( m_MouseButton == MouseButton::RIGHT && !(grfKeyState & MK_RBUTTON) ) ||
294*b1cdbd2cSJim Jagielski ( m_MouseButton == MouseButton::MIDDLE && !(grfKeyState & MK_MBUTTON) ) ||
295*b1cdbd2cSJim Jagielski ( m_MouseButton == MouseButton::LEFT && !(grfKeyState & MK_LBUTTON) ) ||
296*b1cdbd2cSJim Jagielski ( m_MouseButton == 0 && !(grfKeyState & MK_LBUTTON) ) )
297*b1cdbd2cSJim Jagielski {
298*b1cdbd2cSJim Jagielski retVal= DRAGDROP_S_DROP;
299*b1cdbd2cSJim Jagielski }
300*b1cdbd2cSJim Jagielski }
301*b1cdbd2cSJim Jagielski
302*b1cdbd2cSJim Jagielski // fire dropActionChanged event.
303*b1cdbd2cSJim Jagielski // this is actually done by the context, which also detects whether the action
304*b1cdbd2cSJim Jagielski // changed at all
305*b1cdbd2cSJim Jagielski sal_Int8 dropAction= fEscapePressed ? ACTION_NONE :
306*b1cdbd2cSJim Jagielski dndOleKeysToAction( grfKeyState, m_sourceActions);
307*b1cdbd2cSJim Jagielski
308*b1cdbd2cSJim Jagielski sal_Int8 userAction= fEscapePressed ? ACTION_NONE :
309*b1cdbd2cSJim Jagielski dndOleKeysToAction( grfKeyState, -1 );
310*b1cdbd2cSJim Jagielski
311*b1cdbd2cSJim Jagielski static_cast<SourceContext*>(m_currentContext.get())->fire_dropActionChanged(
312*b1cdbd2cSJim Jagielski dropAction, userAction);
313*b1cdbd2cSJim Jagielski
314*b1cdbd2cSJim Jagielski return retVal;
315*b1cdbd2cSJim Jagielski }
316*b1cdbd2cSJim Jagielski
317*b1cdbd2cSJim Jagielski //----------------------------------------------------
318*b1cdbd2cSJim Jagielski /**
319*b1cdbd2cSJim Jagielski */
GiveFeedback(DWORD dwEffect)320*b1cdbd2cSJim Jagielski HRESULT STDMETHODCALLTYPE DragSource::GiveFeedback(
321*b1cdbd2cSJim Jagielski /* [in] */ DWORD
322*b1cdbd2cSJim Jagielski #if defined DBG_CONSOLE_OUT
323*b1cdbd2cSJim Jagielski dwEffect
324*b1cdbd2cSJim Jagielski #endif
325*b1cdbd2cSJim Jagielski )
326*b1cdbd2cSJim Jagielski {
327*b1cdbd2cSJim Jagielski #if defined DBG_CONSOLE_OUT
328*b1cdbd2cSJim Jagielski printf("\nDragSource::GiveFeedback %d", dwEffect);
329*b1cdbd2cSJim Jagielski #endif
330*b1cdbd2cSJim Jagielski
331*b1cdbd2cSJim Jagielski return DRAGDROP_S_USEDEFAULTCURSORS;
332*b1cdbd2cSJim Jagielski }
333*b1cdbd2cSJim Jagielski
334*b1cdbd2cSJim Jagielski // XServiceInfo
getImplementationName()335*b1cdbd2cSJim Jagielski OUString SAL_CALL DragSource::getImplementationName( ) throw (RuntimeException)
336*b1cdbd2cSJim Jagielski {
337*b1cdbd2cSJim Jagielski return OUString(RTL_CONSTASCII_USTRINGPARAM(DNDSOURCE_IMPL_NAME));;
338*b1cdbd2cSJim Jagielski }
339*b1cdbd2cSJim Jagielski // XServiceInfo
supportsService(const OUString & ServiceName)340*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL DragSource::supportsService( const OUString& ServiceName ) throw (RuntimeException)
341*b1cdbd2cSJim Jagielski {
342*b1cdbd2cSJim Jagielski if( ServiceName.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(DNDSOURCE_SERVICE_NAME ))))
343*b1cdbd2cSJim Jagielski return sal_True;
344*b1cdbd2cSJim Jagielski return sal_False;
345*b1cdbd2cSJim Jagielski }
346*b1cdbd2cSJim Jagielski
getSupportedServiceNames()347*b1cdbd2cSJim Jagielski Sequence< OUString > SAL_CALL DragSource::getSupportedServiceNames( ) throw (RuntimeException)
348*b1cdbd2cSJim Jagielski {
349*b1cdbd2cSJim Jagielski OUString names[1]= {OUString(RTL_CONSTASCII_USTRINGPARAM(DNDSOURCE_SERVICE_NAME))};
350*b1cdbd2cSJim Jagielski
351*b1cdbd2cSJim Jagielski return Sequence<OUString>(names, 1);
352*b1cdbd2cSJim Jagielski }
353*b1cdbd2cSJim Jagielski
354*b1cdbd2cSJim Jagielski //----------------------------------------------------
355*b1cdbd2cSJim Jagielski /**This function is called as extra thread from
356*b1cdbd2cSJim Jagielski DragSource::executeDrag. The function
357*b1cdbd2cSJim Jagielski carries out a drag and drop operation by calling
358*b1cdbd2cSJim Jagielski DoDragDrop. The thread also notifies all
359*b1cdbd2cSJim Jagielski XSourceListener.
360*b1cdbd2cSJim Jagielski */
DndOleSTAFunc(LPVOID pParams)361*b1cdbd2cSJim Jagielski unsigned __stdcall DndOleSTAFunc(LPVOID pParams)
362*b1cdbd2cSJim Jagielski {
363*b1cdbd2cSJim Jagielski // The structure contains all arguments for DoDragDrop and other
364*b1cdbd2cSJim Jagielski DragSource *pSource= (DragSource*)pParams;
365*b1cdbd2cSJim Jagielski
366*b1cdbd2cSJim Jagielski // Drag and drop only works in a thread in which OleInitialize is called.
367*b1cdbd2cSJim Jagielski HRESULT hr= OleInitialize( NULL);
368*b1cdbd2cSJim Jagielski
369*b1cdbd2cSJim Jagielski if(SUCCEEDED(hr))
370*b1cdbd2cSJim Jagielski {
371*b1cdbd2cSJim Jagielski // We force the creation of a thread message queue. This is necessary
372*b1cdbd2cSJim Jagielski // for a later call to AttachThreadInput
373*b1cdbd2cSJim Jagielski MSG msgtemp;
374*b1cdbd2cSJim Jagielski PeekMessage( &msgtemp, NULL, WM_USER, WM_USER, PM_NOREMOVE);
375*b1cdbd2cSJim Jagielski
376*b1cdbd2cSJim Jagielski DWORD threadId= GetCurrentThreadId();
377*b1cdbd2cSJim Jagielski
378*b1cdbd2cSJim Jagielski // This thread is attached to the thread that created the window. Hence
379*b1cdbd2cSJim Jagielski // this thread also receives all mouse and keyboard messages which are
380*b1cdbd2cSJim Jagielski // needed by DoDragDrop
381*b1cdbd2cSJim Jagielski AttachThreadInput( threadId , pSource->m_threadIdWindow, TRUE );
382*b1cdbd2cSJim Jagielski
383*b1cdbd2cSJim Jagielski DWORD dwEffect= 0;
384*b1cdbd2cSJim Jagielski hr= DoDragDrop(
385*b1cdbd2cSJim Jagielski pSource->m_spDataObject.get(),
386*b1cdbd2cSJim Jagielski static_cast<IDropSource*>(pSource),
387*b1cdbd2cSJim Jagielski dndActionsToDropEffects( pSource->m_sourceActions),
388*b1cdbd2cSJim Jagielski &dwEffect);
389*b1cdbd2cSJim Jagielski
390*b1cdbd2cSJim Jagielski // #105428 detach my message queue from the other threads
391*b1cdbd2cSJim Jagielski // message queue before calling fire_dragDropEnd else
392*b1cdbd2cSJim Jagielski // the office may appear to hang sometimes
393*b1cdbd2cSJim Jagielski AttachThreadInput( threadId, pSource->m_threadIdWindow, FALSE);
394*b1cdbd2cSJim Jagielski
395*b1cdbd2cSJim Jagielski //--> TRA
396*b1cdbd2cSJim Jagielski // clear the global transferable again
397*b1cdbd2cSJim Jagielski g_XTransferable = Reference< XTransferable >( );
398*b1cdbd2cSJim Jagielski //<-- TRA
399*b1cdbd2cSJim Jagielski
400*b1cdbd2cSJim Jagielski OSL_ENSURE( hr != E_INVALIDARG, "IDataObject impl does not contain valid data");
401*b1cdbd2cSJim Jagielski
402*b1cdbd2cSJim Jagielski //Fire event
403*b1cdbd2cSJim Jagielski sal_Int8 action= hr == DRAGDROP_S_DROP ? dndOleDropEffectsToActions( dwEffect) : ACTION_NONE;
404*b1cdbd2cSJim Jagielski
405*b1cdbd2cSJim Jagielski static_cast<SourceContext*>(pSource->m_currentContext.get())->fire_dragDropEnd(
406*b1cdbd2cSJim Jagielski hr == DRAGDROP_S_DROP ? sal_True : sal_False, action);
407*b1cdbd2cSJim Jagielski
408*b1cdbd2cSJim Jagielski // Destroy SourceContextslkfgj
409*b1cdbd2cSJim Jagielski pSource->m_currentContext= 0;
410*b1cdbd2cSJim Jagielski // Destroy the XTransferable wrapper
411*b1cdbd2cSJim Jagielski pSource->m_spDataObject=0;
412*b1cdbd2cSJim Jagielski
413*b1cdbd2cSJim Jagielski OleUninitialize();
414*b1cdbd2cSJim Jagielski }
415*b1cdbd2cSJim Jagielski
416*b1cdbd2cSJim Jagielski InterlockedDecrement(&pSource->m_RunningDndOperationCount);
417*b1cdbd2cSJim Jagielski
418*b1cdbd2cSJim Jagielski // the DragSource was manually acquired by
419*b1cdbd2cSJim Jagielski // thread starting method DelayedStartDrag
420*b1cdbd2cSJim Jagielski pSource->release();
421*b1cdbd2cSJim Jagielski
422*b1cdbd2cSJim Jagielski return 0;
423*b1cdbd2cSJim Jagielski }
424*b1cdbd2cSJim Jagielski
425*b1cdbd2cSJim Jagielski
426*b1cdbd2cSJim Jagielski
427*b1cdbd2cSJim Jagielski
428