xref: /trunk/main/vcl/aqua/source/dtrans/DropTarget.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _DROPTARGET_HXX_
29*cdf0e10cSrcweir #define _DROPTARGET_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "DataFlavorMapping.hxx"
32*cdf0e10cSrcweir #include <cppuhelper/compbase5.hxx>
33*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DATATRANSFER_DND_XDROPTARGETLISTENR_HPP_
37*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
44*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
45*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <boost/utility.hpp>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <premac.h>
50*cdf0e10cSrcweir #import <Cocoa/Cocoa.h>
51*cdf0e10cSrcweir #include <postmac.h>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir class DropTarget;
54*cdf0e10cSrcweir class AquaSalFrame;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir /* The functions declared in this protocol are actually
57*cdf0e10cSrcweir    declared in vcl/aqua/inc/salframe.h. Because we want
58*cdf0e10cSrcweir    to avoid importing VCL headers in UNO services and
59*cdf0e10cSrcweir    on the other hand want to avoid warnings caused by
60*cdf0e10cSrcweir    gcc complaining about unknowness of these functions
61*cdf0e10cSrcweir    we declare them in a protocol here and cast at the
62*cdf0e10cSrcweir    appropriate places.
63*cdf0e10cSrcweir */
64*cdf0e10cSrcweir @protocol DraggingDestinationHandler
65*cdf0e10cSrcweir -(void)registerDraggingDestinationHandler:(id)theHandler;
66*cdf0e10cSrcweir -(void)unregisterDraggingDestinationHandler:(id)theHandler;
67*cdf0e10cSrcweir @end
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir @interface DropTargetHelper : NSObject
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir   DropTarget* mDropTarget;
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir -(DropTargetHelper*)initWithDropTarget:(DropTarget*)pdt;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
78*cdf0e10cSrcweir -(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
79*cdf0e10cSrcweir -(void)draggingExited:(id <NSDraggingInfo>)sender;
80*cdf0e10cSrcweir -(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender;
81*cdf0e10cSrcweir -(BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
82*cdf0e10cSrcweir -(void)concludeDragOperation:(id <NSDraggingInfo>)sender;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir @end
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir class DropTarget: public cppu::BaseMutex,
88*cdf0e10cSrcweir                   public cppu::WeakComponentImplHelper5< com::sun::star::lang::XInitialization,
89*cdf0e10cSrcweir                                                          com::sun::star::datatransfer::dnd::XDropTarget,
90*cdf0e10cSrcweir                                                          com::sun::star::datatransfer::dnd::XDropTargetDragContext,
91*cdf0e10cSrcweir                                                          com::sun::star::datatransfer::dnd::XDropTargetDropContext,
92*cdf0e10cSrcweir                                                          com::sun::star::lang::XServiceInfo >,
93*cdf0e10cSrcweir                   private boost::noncopyable
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir public:
96*cdf0e10cSrcweir   DropTarget();
97*cdf0e10cSrcweir   virtual ~DropTarget();
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir   // Overrides WeakComponentImplHelper::disposing which is called by
100*cdf0e10cSrcweir   // WeakComponentImplHelper::dispose
101*cdf0e10cSrcweir   // Must be called.
102*cdf0e10cSrcweir   virtual void SAL_CALL disposing();
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir   // XInitialization
105*cdf0e10cSrcweir   virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
106*cdf0e10cSrcweir     throw(com::sun::star::uno::Exception);
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir   // XDropTarget
109*cdf0e10cSrcweir   virtual void SAL_CALL addDropTargetListener( const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetListener >& dtl )
110*cdf0e10cSrcweir     throw(com::sun::star::uno::RuntimeException);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir   virtual void SAL_CALL removeDropTargetListener( const com::sun::star::uno::Reference<  com::sun::star::datatransfer::dnd::XDropTargetListener >& dtl )
113*cdf0e10cSrcweir     throw(com::sun::star::uno::RuntimeException);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir   // Default is not active
116*cdf0e10cSrcweir   virtual sal_Bool SAL_CALL isActive() throw(com::sun::star::uno::RuntimeException);
117*cdf0e10cSrcweir   virtual void SAL_CALL setActive(sal_Bool isActive) throw(com::sun::star::uno::RuntimeException);
118*cdf0e10cSrcweir   virtual sal_Int8 SAL_CALL getDefaultActions() throw(com::sun::star::uno::RuntimeException);
119*cdf0e10cSrcweir   virtual void SAL_CALL setDefaultActions(sal_Int8 actions) throw(com::sun::star::uno::RuntimeException);
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir   // XDropTargetDragContext
122*cdf0e10cSrcweir   virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) throw(com::sun::star::uno::RuntimeException);
123*cdf0e10cSrcweir   virtual void SAL_CALL rejectDrag() throw(com::sun::star::uno::RuntimeException);
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir   // XDropTargetDragContext
126*cdf0e10cSrcweir   virtual void SAL_CALL acceptDrop(sal_Int8 dropOperation) throw (com::sun::star::uno::RuntimeException);
127*cdf0e10cSrcweir   virtual void SAL_CALL rejectDrop() throw (com::sun::star::uno::RuntimeException);
128*cdf0e10cSrcweir   virtual void SAL_CALL dropComplete(sal_Bool success) throw (com::sun::star::uno::RuntimeException);
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir   // XServiceInfo
131*cdf0e10cSrcweir   virtual rtl::OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException);
132*cdf0e10cSrcweir   virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw (com::sun::star::uno::RuntimeException);
133*cdf0e10cSrcweir   virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir   // NSDraggingDestination protocol functions
136*cdf0e10cSrcweir   virtual NSDragOperation draggingEntered(id sender);
137*cdf0e10cSrcweir   virtual NSDragOperation draggingUpdated(id sender);
138*cdf0e10cSrcweir   virtual void draggingExited(id sender);
139*cdf0e10cSrcweir   virtual BOOL prepareForDragOperation(id sender);
140*cdf0e10cSrcweir   virtual BOOL performDragOperation(id sender);
141*cdf0e10cSrcweir   virtual void concludeDragOperation(id sender);
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir   /* If multiple actions are supported by the drag source and
144*cdf0e10cSrcweir      the user did not choose a specific action by pressing a
145*cdf0e10cSrcweir      modifier key choose a default action to be proposed to
146*cdf0e10cSrcweir      the application.
147*cdf0e10cSrcweir   */
148*cdf0e10cSrcweir   sal_Int8 determineDropAction(sal_Int8 dropActions, id sender) const;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir private:
151*cdf0e10cSrcweir   void fire_drop(const com::sun::star::datatransfer::dnd::DropTargetDropEvent& dte);
152*cdf0e10cSrcweir   void fire_dragEnter(const com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee);
153*cdf0e10cSrcweir   void fire_dragExit(const com::sun::star::datatransfer::dnd::DropTargetEvent& dte);
154*cdf0e10cSrcweir   void fire_dragOver(const com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde);
155*cdf0e10cSrcweir   void fire_dropActionChanged(const com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir private:
158*cdf0e10cSrcweir   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetDragContext > mXCurrentDragContext;
159*cdf0e10cSrcweir   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetDropContext > mXCurrentDropContext;
160*cdf0e10cSrcweir   com::sun::star::uno::Reference< com::sun::star::datatransfer::clipboard::XClipboard > mXCurrentDragClipboard;
161*cdf0e10cSrcweir   DataFlavorMapperPtr_t mDataFlavorMapper;
162*cdf0e10cSrcweir   id  mView;
163*cdf0e10cSrcweir   AquaSalFrame* mpFrame;
164*cdf0e10cSrcweir   DropTargetHelper* mDropTargetHelper;
165*cdf0e10cSrcweir   bool mbActive;
166*cdf0e10cSrcweir   sal_Int8 mDragSourceSupportedActions;
167*cdf0e10cSrcweir   sal_Int8 mSelectedDropAction;
168*cdf0e10cSrcweir   sal_Int8 mDefaultActions;
169*cdf0e10cSrcweir };
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir #endif
172