update credits
[LibreOffice.git] / dtrans / source / win32 / dnd / target.hxx
blob98ccb2d14de4cf04bdd3e710053af537e5b0dbd6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _TARGET_HXX_
20 #define _TARGET_HXX_
22 #include <com/sun/star/lang/XInitialization.hpp>
23 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
24 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <cppuhelper/compbase3.hxx>
28 #include <cppuhelper/interfacecontainer.hxx>
29 #include <osl/mutex.hxx>
31 #if defined _MSC_VER
32 #pragma warning(push,1)
33 #endif
34 #include <oleidl.h>
35 #if defined _MSC_VER
36 #pragma warning(pop)
37 #endif
38 #include "globals.hxx"
39 #include "../../inc/DtObjFactory.hxx"
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::uno;
44 using namespace cppu;
45 using namespace osl;
46 using namespace ::com::sun::star::datatransfer;
47 using namespace ::com::sun::star::datatransfer::dnd;
49 // The client
50 // has to call XComponent::dispose. The thread that calls initialize
51 // must also execute the destruction of the instance. This is because
52 // initialize calls OleInitialize and the destructor calls OleUninitialize.
53 // If the service calls OleInitialize then it also calls OleUnitialize when
54 // it is destroyed. Therefore no second instance may exist which was
55 // created in the same thread and still needs OLE.
56 class DropTarget: public MutexDummy,
57 public WeakComponentImplHelper3< XInitialization, XDropTarget, XServiceInfo>
60 private:
61 friend DWORD WINAPI DndTargetOleSTAFunc(LPVOID pParams);
62 // The native window which acts as drop target.
63 // It is set in initialize. In case RegisterDragDrop fails it is set
64 // to NULL
65 HWND m_hWnd; // set by initialize
66 // Holds the thread id of the thread which created the window that is the
67 // drop target. Only used when DropTarget::initialize is called from an MTA
68 // thread
69 DWORD m_threadIdWindow;
70 // This is the thread id of the OLE thread that is created in DropTarget::initialize
71 // when the calling thread is an MTA
72 DWORD m_threadIdTarget;
73 // The handle of the thread that is created in DropTarget::initialize
74 // when the calling thread is an MTA
75 HANDLE m_hOleThread;
76 // The thread id of the thread which called initialize. When the service dies
77 // than m_oleThreadId is used to determine if the service successfully called
78 // OleInitialize. If so then OleUninitialize has to be called.
79 DWORD m_oleThreadId;
80 // An Instance of IDropTargetImpl which receives calls from the system's drag
81 // and drop implementation. It delegate the calls to name alike functions in
82 // this class.
83 IDropTarget* m_pDropTarget;
85 Reference<XComponentContext> m_xContext;
86 // If m_bActive == sal_True then events are fired to XDropTargetListener s,
87 // none otherwise. The default value is sal_True.
88 sal_Bool m_bActive;
89 sal_Int8 m_nDefaultActions;
91 // This value is set when a XDropTargetListener calls accept or reject on
92 // the XDropTargetDropContext or XDropTargetDragContext.
93 // The values are from the DNDConstants group.
94 sal_Int8 m_nCurrentDropAction;
95 // This value is manipulated by the XDropTargetListener
96 sal_Int8 m_nLastDropAction;
98 Reference<XTransferable> m_currentData;
99 // The current action is used to determine if the USER
100 // action has changed (dropActionChanged)
101 // sal_Int8 m_userAction;
102 // Set by listeners when they call XDropTargetDropContext::dropComplete
103 sal_Bool m_bDropComplete;
104 // converts IDataObject objects to XTransferable objects.
105 CDTransObjFactory m_aDataConverter;
106 Reference<XDropTargetDragContext> m_currentDragContext;
107 Reference<XDropTargetDropContext> m_currentDropContext;
110 private:
111 DropTarget();
112 DropTarget(DropTarget&);
113 DropTarget &operator= (DropTarget&);
115 public:
116 DropTarget(const Reference<XComponentContext>& rxContext);
117 virtual ~DropTarget();
119 // Overrides WeakComponentImplHelper::disposing which is called by
120 // WeakComponentImplHelper::dispose
121 // Must be called.
122 virtual void SAL_CALL disposing();
123 // XInitialization
124 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
125 throw(Exception, RuntimeException);
127 // XDropTarget
128 virtual void SAL_CALL addDropTargetListener( const Reference< XDropTargetListener >& dtl )
129 throw(RuntimeException);
130 virtual void SAL_CALL removeDropTargetListener( const Reference< XDropTargetListener >& dtl )
131 throw(RuntimeException);
132 // Default is not active
133 virtual sal_Bool SAL_CALL isActive( ) throw(RuntimeException);
134 virtual void SAL_CALL setActive( sal_Bool isActive ) throw(RuntimeException);
135 virtual sal_Int8 SAL_CALL getDefaultActions( ) throw(RuntimeException);
136 virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) throw(RuntimeException);
138 // XServiceInfo
139 virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException);
140 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
141 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException);
144 // Functions called from the IDropTarget implementation ( m_pDropTarget)
145 virtual HRESULT DragEnter(
146 /* [unique][in] */ IDataObject *pDataObj,
147 /* [in] */ DWORD grfKeyState,
148 /* [in] */ POINTL pt,
149 /* [out][in] */ DWORD *pdwEffect);
151 virtual HRESULT STDMETHODCALLTYPE DragOver(
152 /* [in] */ DWORD grfKeyState,
153 /* [in] */ POINTL pt,
154 /* [out][in] */ DWORD *pdwEffect);
156 virtual HRESULT STDMETHODCALLTYPE DragLeave( ) ;
158 virtual HRESULT STDMETHODCALLTYPE Drop(
159 /* [unique][in] */ IDataObject *pDataObj,
160 /* [in] */ DWORD grfKeyState,
161 /* [in] */ POINTL pt,
162 /* [out][in] */ DWORD *pdwEffect);
165 // Non - interface functions --------------------------------------------------
166 // XDropTargetDropContext delegated from DropContext
168 void _acceptDrop( sal_Int8 dropOperation, const Reference<XDropTargetDropContext>& context);
169 void _rejectDrop( const Reference<XDropTargetDropContext>& context);
170 void _dropComplete( sal_Bool success, const Reference<XDropTargetDropContext>& context);
172 // XDropTargetDragContext delegated from DragContext
173 void _acceptDrag( sal_Int8 dragOperation, const Reference<XDropTargetDragContext>& context);
174 void _rejectDrag( const Reference<XDropTargetDragContext>& context);
177 protected:
178 // Gets the current action dependend on the pressed modifiers, the effects
179 // supported by the drop source (IDropSource) and the default actions of the
180 // drop target (XDropTarget, this class))
181 inline sal_Int8 getFilteredActions( DWORD grfKeyState, DWORD sourceActions);
182 // Only filters with the default actions
183 inline sal_Int8 getFilteredActions( DWORD grfKeyState);
187 void fire_drop( const DropTargetDropEvent& dte);
188 void fire_dragEnter( const DropTargetDragEnterEvent& dtde );
189 void fire_dragExit( const DropTargetEvent& dte );
190 void fire_dragOver( const DropTargetDragEvent& dtde );
191 void fire_dropActionChanged( const DropTargetDragEvent& dtde );
199 #endif
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */