1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DRAGSOURCE_HXX_
25 #define _DRAGSOURCE_HXX_
26 
27 #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
28 #include <com/sun/star/datatransfer/dnd/XDragSourceContext.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <cppuhelper/compbase3.hxx>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <cppuhelper/basemutex.hxx>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <osl/thread.h>
35 #include <com/sun/star/awt/MouseEvent.hpp>
36 
37 #include <boost/utility.hpp>
38 
39 #include <premac.h>
40 #import <Cocoa/Cocoa.h>
41 #include <postmac.h>
42 
43 
44 class DragSource;
45 class AquaSalFrame;
46 
47 /* The functions declared in this protocol are actually
48    declared in vcl/aqua/inc/salframe.h. Because we want
49    to avoid importing VCL headers in UNO services and
50    on the other hand want to avoid warnings caused by
51    gcc complaining about unknowness of these functions
52    we declare them in a protocol here and cast at the
53    appropriate places.
54 */
55 @protocol MouseEventListener
56 -(void)registerMouseEventListener:(id)theHandler;
57 -(void)unregisterMouseEventListener:(id)theHandler;
58 @end
59 
60 
61 @interface DragSourceHelper : NSObject
62 {
63   DragSource* mDragSource;
64 }
65 
66 -(DragSourceHelper*)initWithDragSource: (DragSource*) pds;
67 
68 -(void)mouseDown: (NSEvent*)theEvent;
69 -(void)mouseDragged: (NSEvent*)theEvent;
70 
71 -(unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
72 -(void)draggedImage:(NSImage*)anImage beganAt:(NSPoint)aPoint;
73 -(void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
74 -(void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint;
75 
76 @end
77 
78 
79 class DragSource : public ::cppu::BaseMutex,
80 				   public ::cppu::WeakComponentImplHelper3< com::sun::star::datatransfer::dnd::XDragSource,
81 															com::sun::star::lang::XInitialization,
82 															com::sun::star::lang::XServiceInfo >,
83 				   private ::boost::noncopyable
84 {
85 public:
86   DragSource();
87   virtual ~DragSource();
88 
89   // XInitialization
90   virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
91 	throw(com::sun::star::uno::Exception/*, com::sun::star::uno::RuntimeException*/);
92 
93   // XDragSource
94   virtual sal_Bool SAL_CALL isDragImageSupported(  ) throw(com::sun::star::uno::RuntimeException);
95 
96   virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction)
97 	throw(com::sun::star::lang::IllegalArgumentException, com::sun::star::uno::RuntimeException);
98 
99   virtual void SAL_CALL startDrag( const com::sun::star::datatransfer::dnd::DragGestureEvent& trigger,
100 								   sal_Int8 sourceActions,
101 								   sal_Int32 cursor,
102 								   sal_Int32 image,
103 								   const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& transferable,
104 								   const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener >& listener )
105 	throw(com::sun::star::uno::RuntimeException);
106 
107   // XServiceInfo
108   virtual rtl::OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException);
109   virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw (com::sun::star::uno::RuntimeException);
110   virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
111 
112   virtual void saveMouseEvent(NSEvent* theEvent);
113   virtual unsigned int getSupportedDragOperations(bool isLocal) const;
114 
115 public:
116   // The context notifies the XDragSourceListeners
117   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceContext > mXCurrentContext;
118 
119   id mView;
120   AquaSalFrame* mpFrame;
121   NSEvent* mLastMouseEventBeforeStartDrag;
122   DragSourceHelper* mDragSourceHelper;
123   com::sun::star::awt::MouseEvent mMouseEvent;
124   com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > mXTransferable;
125   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener > mXDragSrcListener;
126   // The mouse button that set off the drag and drop operation
127   short m_MouseButton;
128   sal_Int8 mDragSourceActions;
129 
130   static com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > g_XTransferable;
131   static NSView* g_DragSourceView;
132   static bool    g_DropSuccessSet;
133   static bool    g_DropSuccess;
134 
135 };
136 
137 
138 #endif
139