xref: /trunk/main/vcl/aqua/source/dtrans/DragSource.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
92   // XDragSource
93   virtual sal_Bool SAL_CALL isDragImageSupported(  );
94 
95   virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction);
96 
97   virtual void SAL_CALL startDrag( const com::sun::star::datatransfer::dnd::DragGestureEvent& trigger,
98                                    sal_Int8 sourceActions,
99                                    sal_Int32 cursor,
100                                    sal_Int32 image,
101                                    const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& transferable,
102                                    const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener >& listener );
103 
104   // XServiceInfo
105   virtual rtl::OUString SAL_CALL getImplementationName();
106   virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName);
107   virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames();
108 
109   virtual void saveMouseEvent(NSEvent* theEvent);
110   virtual unsigned int getSupportedDragOperations(bool isLocal) const;
111 
112 public:
113   // The context notifies the XDragSourceListeners
114   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceContext > mXCurrentContext;
115 
116   id mView;
117   AquaSalFrame* mpFrame;
118   NSEvent* mLastMouseEventBeforeStartDrag;
119   DragSourceHelper* mDragSourceHelper;
120   com::sun::star::awt::MouseEvent mMouseEvent;
121   com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > mXTransferable;
122   com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener > mXDragSrcListener;
123   // The mouse button that set off the drag and drop operation
124   short m_MouseButton;
125   sal_Int8 mDragSourceActions;
126 
127   static com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > g_XTransferable;
128   static NSView* g_DragSourceView;
129   static bool    g_DropSuccessSet;
130   static bool    g_DropSuccess;
131 
132 };
133 
134 
135 #endif
136