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 _DRAGSOURCE_HXX_
29 #define _DRAGSOURCE_HXX_
30 
31 #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
32 #include <com/sun/star/datatransfer/dnd/XDragSourceContext.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <cppuhelper/compbase3.hxx>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <cppuhelper/basemutex.hxx>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <osl/thread.h>
39 #include <com/sun/star/awt/MouseEvent.hpp>
40 
41 #include <boost/utility.hpp>
42 
43 #include <premac.h>
44 #import <Cocoa/Cocoa.h>
45 #include <postmac.h>
46 
47 
48 class DragSource;
49 class AquaSalFrame;
50 
51 /* The functions declared in this protocol are actually
52    declared in vcl/aqua/inc/salframe.h. Because we want
53    to avoid importing VCL headers in UNO services and
54    on the other hand want to avoid warnings caused by
55    gcc complaining about unknowness of these functions
56    we declare them in a protocol here and cast at the
57    appropriate places.
58 */
59 @protocol MouseEventListener
60 -(void)registerMouseEventListener:(id)theHandler;
61 -(void)unregisterMouseEventListener:(id)theHandler;
62 @end
63 
64 
65 @interface DragSourceHelper : NSObject
66 {
67   DragSource* mDragSource;
68 }
69 
70 -(DragSourceHelper*)initWithDragSource: (DragSource*) pds;
71 
72 -(void)mouseDown: (NSEvent*)theEvent;
73 -(void)mouseDragged: (NSEvent*)theEvent;
74 
75 -(unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
76 -(void)draggedImage:(NSImage*)anImage beganAt:(NSPoint)aPoint;
77 -(void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
78 -(void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint;
79 
80 @end
81 
82 
83 class DragSource : public ::cppu::BaseMutex,
84 				   public ::cppu::WeakComponentImplHelper3< com::sun::star::datatransfer::dnd::XDragSource,
85 															com::sun::star::lang::XInitialization,
86 															com::sun::star::lang::XServiceInfo >,
87 				   private ::boost::noncopyable
88 {
89 public:
90   DragSource();
91   virtual ~DragSource();
92 
93   // XInitialization
94   virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
95 	throw(com::sun::star::uno::Exception/*, com::sun::star::uno::RuntimeException*/);
96 
97   // XDragSource
98   virtual sal_Bool SAL_CALL isDragImageSupported(  ) throw(com::sun::star::uno::RuntimeException);
99 
100   virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction)
101 	throw(com::sun::star::lang::IllegalArgumentException, com::sun::star::uno::RuntimeException);
102 
103   virtual void SAL_CALL startDrag( const com::sun::star::datatransfer::dnd::DragGestureEvent& trigger,
104 								   sal_Int8 sourceActions,
105 								   sal_Int32 cursor,
106 								   sal_Int32 image,
107 								   const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& transferable,
108 								   const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener >& listener )
109 	throw(com::sun::star::uno::RuntimeException);
110 
111   // XServiceInfo
112   virtual rtl::OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException);
113   virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw (com::sun::star::uno::RuntimeException);
114   virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
115 
116   virtual void saveMouseEvent(NSEvent* theEvent);
117   virtual unsigned int getSupportedDragOperations(bool isLocal) const;
118 
119 public:
120   // The context notifies the XDragSourceListeners
121   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceContext > mXCurrentContext;
122 
123   id mView;
124   AquaSalFrame* mpFrame;
125   NSEvent* mLastMouseEventBeforeStartDrag;
126   DragSourceHelper* mDragSourceHelper;
127   com::sun::star::awt::MouseEvent mMouseEvent;
128   com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > mXTransferable;
129   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener > mXDragSrcListener;
130   // The mouse button that set off the drag and drop operation
131   short m_MouseButton;
132   sal_Int8 mDragSourceActions;
133 
134   static com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > g_XTransferable;
135   static NSView* g_DragSourceView;
136   static bool    g_DropSuccessSet;
137   static bool    g_DropSuccess;
138 
139 };
140 
141 
142 #endif
143