Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / osx / DragSource.hxx
blob491716d87f4cc22d099c64aa74d44706d62a9fe6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_OSX_DRAGSOURCE_HXX
21 #define INCLUDED_VCL_OSX_DRAGSOURCE_HXX
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/compbase3.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>
33 #include <boost/utility.hpp>
35 #include <premac.h>
36 #import <Cocoa/Cocoa.h>
37 #include <postmac.h>
39 class DragSource;
40 class AquaSalFrame;
42 /* The functions declared in this protocol are actually
43 declared in vcl/inc/osx/salframe.h. Because we want
44 to avoid importing VCL headers in UNO services and
45 on the other hand want to avoid warnings caused by
46 gcc complaining about unknowness of these functions
47 we declare them in a protocol here and cast at the
48 appropriate places.
50 @protocol MouseEventListener
51 -(void)registerMouseEventListener:(id)theHandler;
52 -(void)unregisterMouseEventListener:(id)theHandler;
53 @end
55 @interface DragSourceHelper : NSObject
57 DragSource* mDragSource;
60 -(DragSourceHelper*)initWithDragSource: (DragSource*) pds;
62 -(void)mouseDown: (NSEvent*)theEvent;
63 -(void)mouseDragged: (NSEvent*)theEvent;
65 -(unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
66 -(void)draggedImage:(NSImage*)anImage beganAt:(NSPoint)aPoint;
67 -(void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
68 -(void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint;
70 @end
72 class DragSource : public ::cppu::BaseMutex,
73 public ::cppu::WeakComponentImplHelper3< com::sun::star::datatransfer::dnd::XDragSource,
74 com::sun::star::lang::XInitialization,
75 com::sun::star::lang::XServiceInfo >,
76 private ::boost::noncopyable
78 public:
79 DragSource();
80 virtual ~DragSource();
82 // XInitialization
83 virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
84 throw(com::sun::star::uno::Exception, std::exception/*, com::sun::star::uno::RuntimeException*/) SAL_OVERRIDE;
86 // XDragSource
87 virtual sal_Bool SAL_CALL isDragImageSupported( ) throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
89 virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction)
90 throw(com::sun::star::lang::IllegalArgumentException, com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
92 virtual void SAL_CALL startDrag( const com::sun::star::datatransfer::dnd::DragGestureEvent& trigger,
93 sal_Int8 sourceActions,
94 sal_Int32 cursor,
95 sal_Int32 image,
96 const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& transferable,
97 const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener >& listener )
98 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
100 // XServiceInfo
101 virtual OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
102 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 virtual com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 void saveMouseEvent(NSEvent* theEvent);
106 unsigned int getSupportedDragOperations(bool isLocal) const;
108 public:
109 // The context notifies the XDragSourceListeners
110 com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceContext > mXCurrentContext;
112 id mView;
113 AquaSalFrame* mpFrame;
114 NSEvent* mLastMouseEventBeforeStartDrag;
115 DragSourceHelper* mDragSourceHelper;
116 com::sun::star::awt::MouseEvent mMouseEvent;
117 com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > mXTransferable;
118 com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDragSourceListener > mXDragSrcListener;
119 // The mouse button that set off the drag and drop operation
120 short m_MouseButton;
121 sal_Int8 mDragSourceActions;
123 static com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable > g_XTransferable;
124 static NSView* g_DragSourceView;
125 static bool g_DropSuccessSet;
126 static bool g_DropSuccess;
130 #endif // INCLUDED_VCL_OSX_DRAGSOURCE_HXX
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */