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