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 
24 #ifndef _DROPTARGET_HXX_
25 #define _DROPTARGET_HXX_
26 
27 #include "DataFlavorMapping.hxx"
28 #include <cppuhelper/compbase5.hxx>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
31 
32 #ifndef _COM_SUN_STAR_DATATRANSFER_DND_XDROPTARGETLISTENR_HPP_
33 #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp>
34 #endif
35 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
36 #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
37 #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp>
38 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <cppuhelper/basemutex.hxx>
41 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
42 
43 #include <boost/utility.hpp>
44 
45 #include <premac.h>
46 #import <Cocoa/Cocoa.h>
47 #include <postmac.h>
48 
49 class DropTarget;
50 class AquaSalFrame;
51 
52 /* The functions declared in this protocol are actually
53    declared in vcl/aqua/inc/salframe.h. Because we want
54    to avoid importing VCL headers in UNO services and
55    on the other hand want to avoid warnings caused by
56    gcc complaining about unknowness of these functions
57    we declare them in a protocol here and cast at the
58    appropriate places.
59 */
60 @protocol DraggingDestinationHandler
61 -(void)registerDraggingDestinationHandler:(id)theHandler;
62 -(void)unregisterDraggingDestinationHandler:(id)theHandler;
63 @end
64 
65 
66 @interface DropTargetHelper : NSObject
67 {
68   DropTarget* mDropTarget;
69 }
70 
71 -(DropTargetHelper*)initWithDropTarget:(DropTarget*)pdt;
72 
73 -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
74 -(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
75 -(void)draggingExited:(id <NSDraggingInfo>)sender;
76 -(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender;
77 -(BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
78 -(void)concludeDragOperation:(id <NSDraggingInfo>)sender;
79 
80 @end
81 
82 
83 class DropTarget: public cppu::BaseMutex,
84 				  public cppu::WeakComponentImplHelper5< com::sun::star::lang::XInitialization,
85 														 com::sun::star::datatransfer::dnd::XDropTarget,
86 														 com::sun::star::datatransfer::dnd::XDropTargetDragContext,
87 														 com::sun::star::datatransfer::dnd::XDropTargetDropContext,
88 														 com::sun::star::lang::XServiceInfo >,
89 				  private boost::noncopyable
90 {
91 public:
92   DropTarget();
93   virtual ~DropTarget();
94 
95   // Overrides WeakComponentImplHelper::disposing which is called by
96   // WeakComponentImplHelper::dispose
97   // Must be called.
98   virtual void SAL_CALL disposing();
99 
100   // XInitialization
101   virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
102 	throw(com::sun::star::uno::Exception);
103 
104   // XDropTarget
105   virtual void SAL_CALL addDropTargetListener( const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetListener >& dtl )
106 	throw(com::sun::star::uno::RuntimeException);
107 
108   virtual void SAL_CALL removeDropTargetListener( const com::sun::star::uno::Reference<  com::sun::star::datatransfer::dnd::XDropTargetListener >& dtl )
109 	throw(com::sun::star::uno::RuntimeException);
110 
111   // Default is not active
112   virtual sal_Bool SAL_CALL isActive() throw(com::sun::star::uno::RuntimeException);
113   virtual void SAL_CALL setActive(sal_Bool isActive) throw(com::sun::star::uno::RuntimeException);
114   virtual sal_Int8 SAL_CALL getDefaultActions() throw(com::sun::star::uno::RuntimeException);
115   virtual void SAL_CALL setDefaultActions(sal_Int8 actions) throw(com::sun::star::uno::RuntimeException);
116 
117   // XDropTargetDragContext
118   virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) throw(com::sun::star::uno::RuntimeException);
119   virtual void SAL_CALL rejectDrag() throw(com::sun::star::uno::RuntimeException);
120 
121   // XDropTargetDragContext
122   virtual void SAL_CALL acceptDrop(sal_Int8 dropOperation) throw (com::sun::star::uno::RuntimeException);
123   virtual void SAL_CALL rejectDrop() throw (com::sun::star::uno::RuntimeException);
124   virtual void SAL_CALL dropComplete(sal_Bool success) throw (com::sun::star::uno::RuntimeException);
125 
126   // XServiceInfo
127   virtual rtl::OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException);
128   virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw (com::sun::star::uno::RuntimeException);
129   virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
130 
131   // NSDraggingDestination protocol functions
132   virtual NSDragOperation draggingEntered(id sender);
133   virtual NSDragOperation draggingUpdated(id sender);
134   virtual void draggingExited(id sender);
135   virtual BOOL prepareForDragOperation(id sender);
136   virtual BOOL performDragOperation();
137   virtual void concludeDragOperation(id sender);
138 
139   /* If multiple actions are supported by the drag source and
140 	 the user did not choose a specific action by pressing a
141 	 modifier key choose a default action to be proposed to
142 	 the application.
143   */
144   sal_Int8 determineDropAction(sal_Int8 dropActions, id sender) const;
145 
146 private:
147   void fire_drop(const com::sun::star::datatransfer::dnd::DropTargetDropEvent& dte);
148   void fire_dragEnter(const com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee);
149   void fire_dragExit(const com::sun::star::datatransfer::dnd::DropTargetEvent& dte);
150   void fire_dragOver(const com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde);
151   void fire_dropActionChanged(const com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde);
152 
153 private:
154   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetDragContext > mXCurrentDragContext;
155   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetDropContext > mXCurrentDropContext;
156   com::sun::star::uno::Reference< com::sun::star::datatransfer::clipboard::XClipboard > mXCurrentDragClipboard;
157   DataFlavorMapperPtr_t mDataFlavorMapper;
158   id  mView;
159   AquaSalFrame* mpFrame;
160   DropTargetHelper* mDropTargetHelper;
161   bool mbActive;
162   sal_Int8 mDragSourceSupportedActions;
163   sal_Int8 mSelectedDropAction;
164   sal_Int8 mDefaultActions;
165 };
166 
167 #endif
168