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