1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_VCL_OSX_DRAGSOURCE_HXX
21 #define INCLUDED_VCL_OSX_DRAGSOURCE_HXX
22 
23 #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
24 #include <com/sun/star/datatransfer/dnd/XDragSourceContext.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <cppuhelper/compbase.hxx>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <cppuhelper/basemutex.hxx>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <osl/thread.h>
31 #include <com/sun/star/awt/MouseEvent.hpp>
32 
33 #include <premac.h>
34 #import <Cocoa/Cocoa.h>
35 #include <postmac.h>
36 
37 class DragSource;
38 class AquaSalFrame;
39 
40 /* The functions declared in this protocol are actually
41    declared in vcl/inc/osx/salframe.h. Because we want
42    to avoid importing VCL headers in UNO services and
43    on the other hand want to avoid warnings caused by
44    gcc complaining about unknowness of these functions
45    we declare them in a protocol here and cast at the
46    appropriate places.
47 */
48 @protocol MouseEventListener
49 -(void)registerMouseEventListener:(id)theHandler;
50 -(void)unregisterMouseEventListener:(id)theHandler;
51 @end
52 
53 @interface DragSourceHelper : NSObject
54 {
55   DragSource* mDragSource;
56 }
57 
58 -(DragSourceHelper*)initWithDragSource: (DragSource*) pds;
59 
60 -(void)mouseDown: (NSEvent*)theEvent;
61 -(void)mouseDragged: (NSEvent*)theEvent;
62 
63 -(unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
64 -(void)draggedImage:(NSImage*)anImage beganAt:(NSPoint)aPoint;
65 -(void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
66 -(void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint;
67 
68 @end
69 
70 class DragSource : public ::cppu::BaseMutex,
71                    public ::cppu::WeakComponentImplHelper< css::datatransfer::dnd::XDragSource,
72                                                             css::lang::XInitialization,
73                                                             css::lang::XServiceInfo >
74 {
75 public:
76   DragSource();
77   virtual ~DragSource() override;
78   DragSource(const DragSource&) = delete;
79   DragSource& operator=(const DragSource&) = delete;
80 
81   // XInitialization
82   virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
83 
84   // XDragSource
85   virtual sal_Bool SAL_CALL isDragImageSupported(  ) override;
86 
87   virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction) override;
88 
89   virtual void SAL_CALL startDrag( const css::datatransfer::dnd::DragGestureEvent& trigger,
90                                    sal_Int8 sourceActions,
91                                    sal_Int32 cursor,
92                                    sal_Int32 image,
93                                    const css::uno::Reference< css::datatransfer::XTransferable >& transferable,
94                                    const css::uno::Reference< css::datatransfer::dnd::XDragSourceListener >& listener ) override;
95 
96   // XServiceInfo
97   virtual OUString SAL_CALL getImplementationName() override;
98   virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
99   virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
100 
101   void saveMouseEvent(NSEvent* theEvent);
102   unsigned int getSupportedDragOperations(bool isLocal) const;
103 
104 public:
105   // The context notifies the XDragSourceListeners
106   css::uno::Reference< css::datatransfer::dnd::XDragSourceContext > mXCurrentContext;
107 
108   id mView;
109   AquaSalFrame* mpFrame;
110   NSEvent* mLastMouseEventBeforeStartDrag;
111   DragSourceHelper* mDragSourceHelper;
112   css::awt::MouseEvent mMouseEvent;
113   css::uno::Reference< css::datatransfer::XTransferable > mXTransferable;
114   css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mXDragSrcListener;
115   // The mouse button that set off the drag and drop operation
116   short m_MouseButton;
117   sal_Int8 mDragSourceActions;
118 
119   static css::uno::Reference< css::datatransfer::XTransferable > g_XTransferable;
120   static NSView* g_DragSourceView;
121   static bool    g_DropSuccessSet;
122   static bool    g_DropSuccess;
123 
124 };
125 
126 #endif // INCLUDED_VCL_OSX_DRAGSOURCE_HXX
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
129