xref: /trunk/main/dtrans/source/os2/dnd/DropTarget.hxx (revision cc13e73e)
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 _DROPTARGET_HXX_
24 #define _DROPTARGET_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/XDropTargetDragContext.hpp>
29 #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp>
30 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 
33 #include <cppuhelper/basemutex.hxx>
34 #include <cppuhelper/compbase5.hxx>
35 #include <cppuhelper/interfacecontainer.hxx>
36 #include <osl/mutex.hxx>
37 
38 #include "globals.hxx"
39 
40 
41 using namespace cppu;
42 using namespace osl;
43 using namespace rtl;
44 using namespace com::sun::star::datatransfer;
45 using namespace com::sun::star::datatransfer::dnd;
46 using namespace com::sun::star::lang;
47 using namespace com::sun::star::uno;
48 
49 
50 // The client
51 // has to call XComponent::dispose. The thread that calls initialize
52 // must also execute the destruction of the instance. This is because
53 // initialize calls OleInitialize and the destructor calls OleUninitialize.
54 // If the service calls OleInitialize then it also calls OleUnitialize when
55 // it is destroyed. Therefore no second instance may exist which was
56 // created in the same thread and still needs OLE.
57 class DropTarget: public cppu::BaseMutex,
58         public WeakComponentImplHelper5< XInitialization,
59         XDropTarget,
60         XDropTargetDragContext,
61         XDropTargetDropContext,
62         XServiceInfo>
63 {
64 private:
65     Reference<XMultiServiceFactory> m_serviceFactory;
66     // The native window which acts as drop target.
67     HWND m_hWnd;
68     POINTL ptlMouse;
69     // OS/2 does not provide a DM_DRAGENTER message, provide emulation
70     bool        dragEnterEmulation;
71     // If mbActive == sal_True then events are fired to XDropTargetListener s,
72     // none otherwise. The default value is sal_True.
73     bool        mbActive;
74     sal_Int8    mDragSourceSupportedActions;
75     sal_Int8    mSelectedDropAction;
76     sal_Int8    mDefaultActions;
77     Reference<XTransferable> mXTransferable;
78 
79 public:
80     DropTarget( const Reference<XMultiServiceFactory>& sf);
81     virtual ~DropTarget();
82 
83     // Overrides WeakComponentImplHelper::disposing which is called by
84     // WeakComponentImplHelper::dispose
85     // Must be called.
86     virtual void SAL_CALL disposing();
87 
88     // XInitialization
89     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments)
90         throw(Exception);
91 
92     // XDropTarget
93     virtual void SAL_CALL addDropTargetListener( const Reference< XDropTargetListener >& dtl )
94         throw(RuntimeException);
95     virtual void SAL_CALL removeDropTargetListener( const Reference<  XDropTargetListener >& dtl )
96         throw(RuntimeException);
97 
98     // Default is not active
99     virtual sal_Bool SAL_CALL isActive() throw(RuntimeException);
100     virtual void SAL_CALL setActive(sal_Bool) throw(RuntimeException);
101     virtual sal_Int8 SAL_CALL getDefaultActions() throw(RuntimeException);
102     virtual void SAL_CALL setDefaultActions(sal_Int8) throw(RuntimeException);
103 
104     // XDropTargetDragContext
105     virtual void SAL_CALL acceptDrag( sal_Int8) throw(RuntimeException);
106     virtual void SAL_CALL rejectDrag() throw(RuntimeException);
107 
108     // XDropTargetDropContext
109     virtual void SAL_CALL acceptDrop(sal_Int8) throw (RuntimeException);
110     virtual void SAL_CALL rejectDrop() throw (RuntimeException);
111     virtual void SAL_CALL dropComplete(sal_Bool) throw (RuntimeException);
112 
113     // XServiceInfo
114     virtual rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException);
115     virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw (RuntimeException);
116     virtual Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
117 
118     // OS/2 window messaging handlers
119     MRESULT dragEnter( PDRAGINFO dragInfo);
120     MRESULT dragOver( PDRAGINFO dragInfo);
121     MRESULT dragLeave( PDRAGINFO dragInfo);
122     MRESULT drop( PDRAGINFO dragInfo);
123     MRESULT renderComplete( PDRAGTRANSFER);
124 
125 public:
126     // default window frame procedure
127     PFNWP defWndProc;
128 
129 private:
130     void fire_drop(const DropTargetDropEvent& dte);
131     void fire_dragEnter(const DropTargetDragEnterEvent& dtdee);
132     void fire_dragExit(const DropTargetEvent& dte);
133     void fire_dragOver(const DropTargetDragEvent& dtde);
134     void fire_dropActionChanged(const DropTargetDragEvent& dtde);
135 
136 };
137 #endif // _DROPTARGET_HXX_
138