LibreOffice Module dtrans (master)  1
target.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #pragma once
20 
21 #include <com/sun/star/lang/XInitialization.hpp>
22 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
23 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 
26 #include <cppuhelper/compbase.hxx>
28 #include <osl/mutex.hxx>
29 
30 #include <oleidl.h>
31 #include "globals.hxx"
32 
33 namespace com::sun::star::uno { class XComponentContext; }
34 
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::uno;
37 using namespace cppu;
38 using namespace osl;
39 using namespace ::com::sun::star::datatransfer;
40 using namespace ::com::sun::star::datatransfer::dnd;
41 
42 // The client
43 // has to call XComponent::dispose. The thread that calls initialize
44 // must also execute the destruction of the instance. This is because
45 // initialize calls OleInitialize and the destructor calls OleUninitialize.
46 // If the service calls OleInitialize then it also calls OleUnitialize when
47 // it is destroyed. Therefore no second instance may exist which was
48 // created in the same thread and still needs OLE.
49 class DropTarget: public MutexDummy,
50  public WeakComponentImplHelper< XInitialization, XDropTarget, XServiceInfo>
51 
52 {
53 private:
54  friend DWORD WINAPI DndTargetOleSTAFunc(LPVOID pParams);
55  // The native window which acts as drop target.
56  // It is set in initialize. In case RegisterDragDrop fails it is set
57  // to NULL
58  HWND m_hWnd; // set by initialize
59  // Holds the thread id of the thread which created the window that is the
60  // drop target. Only used when DropTarget::initialize is called from an MTA
61  // thread
63  // This is the thread id of the OLE thread that is created in DropTarget::initialize
64  // when the calling thread is an MTA
66  // The handle of the thread that is created in DropTarget::initialize
67  // when the calling thread is an MTA
68  HANDLE m_hOleThread;
69  // The thread id of the thread which called initialize. When the service dies
70  // than m_oleThreadId is used to determine if the service successfully called
71  // OleInitialize. If so then OleUninitialize has to be called.
73  // An Instance of IDropTargetImpl which receives calls from the system's drag
74  // and drop implementation. It delegate the calls to name alike functions in
75  // this class.
76  IDropTarget* m_pDropTarget;
77 
79  // If m_bActive == sal_True then events are fired to XDropTargetListener s,
80  // none otherwise. The default value is sal_True.
81  bool m_bActive;
83 
84  // This value is set when a XDropTargetListener calls accept or reject on
85  // the XDropTargetDropContext or XDropTargetDragContext.
86  // The values are from the DNDConstants group.
88  // This value is manipulated by the XDropTargetListener
90 
91  Reference<XTransferable> m_currentData;
92  // The current action is used to determine if the USER
93  // action has changed (dropActionChanged)
94 // sal_Int8 m_userAction;
95  // Set by listeners when they call XDropTargetDropContext::dropComplete
97  Reference<XDropTargetDragContext> m_currentDragContext;
98  Reference<XDropTargetDropContext> m_currentDropContext;
99 
100 public:
101  explicit DropTarget(const Reference<XComponentContext>& rxContext);
102  virtual ~DropTarget() override;
103  DropTarget(DropTarget const &) = delete;
104  DropTarget &operator= (DropTarget const &) = delete;
105 
106  // Overrides WeakComponentImplHelper::disposing which is called by
107  // WeakComponentImplHelper::dispose
108  // Must be called.
109  virtual void SAL_CALL disposing() override;
110  // XInitialization
111  virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
112 
113  // XDropTarget
114  virtual void SAL_CALL addDropTargetListener( const Reference< XDropTargetListener >& dtl ) override;
115  virtual void SAL_CALL removeDropTargetListener( const Reference< XDropTargetListener >& dtl ) override;
116  // Default is not active
117  virtual sal_Bool SAL_CALL isActive( ) override;
118  virtual void SAL_CALL setActive( sal_Bool isActive ) override;
119  virtual sal_Int8 SAL_CALL getDefaultActions( ) override;
120  virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) override;
121 
122  // XServiceInfo
123  virtual OUString SAL_CALL getImplementationName( ) override;
124  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
125  virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
126 
127  // Functions called from the IDropTarget implementation ( m_pDropTarget)
128  virtual HRESULT DragEnter(
129  /* [unique][in] */ IDataObject *pDataObj,
130  /* [in] */ DWORD grfKeyState,
131  /* [in] */ POINTL pt,
132  /* [out][in] */ DWORD *pdwEffect);
133 
134  virtual HRESULT STDMETHODCALLTYPE DragOver(
135  /* [in] */ DWORD grfKeyState,
136  /* [in] */ POINTL pt,
137  /* [out][in] */ DWORD *pdwEffect);
138 
139  virtual HRESULT STDMETHODCALLTYPE DragLeave( ) ;
140 
141  virtual HRESULT STDMETHODCALLTYPE Drop(
142  /* [unique][in] */ IDataObject *pDataObj,
143  /* [in] */ DWORD grfKeyState,
144  /* [in] */ POINTL pt,
145  /* [out][in] */ DWORD *pdwEffect);
146 
147 // Non - interface functions --------------------------------------------------
148 // XDropTargetDropContext delegated from DropContext
149 
150  void _acceptDrop( sal_Int8 dropOperation, const Reference<XDropTargetDropContext>& context);
151  void _rejectDrop( const Reference<XDropTargetDropContext>& context);
152  void _dropComplete( bool success, const Reference<XDropTargetDropContext>& context);
153 
154 // XDropTargetDragContext delegated from DragContext
155  void _acceptDrag( sal_Int8 dragOperation, const Reference<XDropTargetDragContext>& context);
156  void _rejectDrag( const Reference<XDropTargetDragContext>& context);
157 
158 protected:
159  // Gets the current action dependent on the pressed modifiers, the effects
160  // supported by the drop source (IDropSource) and the default actions of the
161  // drop target (XDropTarget, this class))
162  inline sal_Int8 getFilteredActions( DWORD grfKeyState, DWORD sourceActions);
163  // Only filters with the default actions
164  inline sal_Int8 getFilteredActions( DWORD grfKeyState);
165 
166  void fire_drop( const DropTargetDropEvent& dte);
167  void fire_dragEnter( const DropTargetDragEnterEvent& dtde );
168  void fire_dragExit( const DropTargetEvent& dte );
169  void fire_dragOver( const DropTargetDragEvent& dtde );
170  void fire_dropActionChanged( const DropTargetDragEvent& dtde );
171 
172 };
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DWORD m_oleThreadId
Definition: target.hxx:72
signed char sal_Int8
Reference< XDropTargetDropContext > m_currentDropContext
Definition: target.hxx:98
sal_Int8 m_nDefaultActions
Definition: target.hxx:82
Reference< XComponentContext > m_xContext
Definition: target.hxx:78
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
DWORD m_threadIdTarget
Definition: target.hxx:65
IDropTarget * m_pDropTarget
Definition: target.hxx:76
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool m_bActive
Definition: target.hxx:81
unsigned char sal_Bool
bool m_bDropComplete
Definition: target.hxx:96
DWORD WINAPI DndTargetOleSTAFunc(LPVOID pParams)
Definition: target.cxx:191
sal_Int8 m_nLastDropAction
Definition: target.hxx:89
Reference< XDropTargetDragContext > m_currentDragContext
Definition: target.hxx:97
HANDLE m_hOleThread
Definition: target.hxx:68
bool isActive()
Reference< XTransferable > m_currentData
Definition: target.hxx:91
void setActive(bool bActive)
HWND m_hWnd
Definition: target.hxx:58
sal_Int8 m_nCurrentDropAction
Definition: target.hxx:87
DWORD m_threadIdWindow
Definition: target.hxx:62