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