1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_DROPTARGET_HXX
21 #define INCLUDED_VCL_OSX_DROPTARGET_HXX
23 #include "DataFlavorMapping.hxx"
24 #include <cppuhelper/compbase5.hxx>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
28 #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp>
29 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
30 #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
31 #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp>
32 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <cppuhelper/basemutex.hxx>
35 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
37 #include <boost/utility.hpp>
40 #import <Cocoa/Cocoa.h>
46 /* The functions declared in this protocol are actually
47 declared in vcl/inc/osx/salframe.h. Because we want
48 to avoid importing VCL headers in UNO services and
49 on the other hand want to avoid warnings caused by
50 gcc complaining about unknowness of these functions
51 we declare them in a protocol here and cast at the
54 @protocol DraggingDestinationHandler
55 -(void)registerDraggingDestinationHandler
:(id
)theHandler
;
56 -(void)unregisterDraggingDestinationHandler
:(id
)theHandler
;
59 @interface DropTargetHelper
: NSObject
61 DropTarget
* mDropTarget
;
64 -(DropTargetHelper
*)initWithDropTarget
:(DropTarget
*)pdt
;
66 -(NSDragOperation
)draggingEntered
:(id
<NSDraggingInfo
>)sender
;
67 -(NSDragOperation
)draggingUpdated
:(id
<NSDraggingInfo
>)sender
;
68 -(void)draggingExited
:(id
<NSDraggingInfo
>)sender
;
69 -(BOOL
)prepareForDragOperation
:(id
<NSDraggingInfo
>)sender
;
70 -(BOOL
)performDragOperation
:(id
<NSDraggingInfo
>)sender
;
71 -(void)concludeDragOperation
:(id
<NSDraggingInfo
>)sender
;
75 class DropTarget
: public cppu::BaseMutex
,
76 public cppu::WeakComponentImplHelper5
< com::sun::star::lang::XInitialization
,
77 com::sun::star::datatransfer::dnd::XDropTarget
,
78 com::sun::star::datatransfer::dnd::XDropTargetDragContext
,
79 com::sun::star::datatransfer::dnd::XDropTargetDropContext
,
80 com::sun::star::lang::XServiceInfo
>,
81 private boost::noncopyable
85 virtual ~DropTarget();
87 // Overrides WeakComponentImplHelper::disposing which is called by
88 // WeakComponentImplHelper::dispose
90 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
93 virtual void SAL_CALL
initialize( const com::sun::star::uno::Sequence
< com::sun::star::uno::Any
>& aArguments
)
94 throw(com::sun::star::uno::Exception
, std::exception
) SAL_OVERRIDE
;
97 virtual void SAL_CALL
addDropTargetListener( const com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetListener
>& dtl
)
98 throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
100 virtual void SAL_CALL
removeDropTargetListener( const com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetListener
>& dtl
)
101 throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
103 // Default is not active
104 virtual sal_Bool SAL_CALL
isActive() throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
105 virtual void SAL_CALL
setActive(sal_Bool isActive
) throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
106 virtual sal_Int8 SAL_CALL
getDefaultActions() throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
107 virtual void SAL_CALL
setDefaultActions(sal_Int8 actions
) throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
109 // XDropTargetDragContext
110 virtual void SAL_CALL
acceptDrag(sal_Int8 dragOperation
) throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
111 virtual void SAL_CALL
rejectDrag() throw(com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
113 // XDropTargetDragContext
114 virtual void SAL_CALL
acceptDrop(sal_Int8 dropOperation
) throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
115 virtual void SAL_CALL
rejectDrop() throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
116 virtual void SAL_CALL
dropComplete(sal_Bool success
) throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 virtual OUString SAL_CALL
getImplementationName() throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
120 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
121 virtual com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 // NSDraggingDestination protocol functions
124 NSDragOperation
draggingEntered(id sender
);
125 NSDragOperation
draggingUpdated(id sender
);
126 void draggingExited(id sender
);
127 static BOOL
prepareForDragOperation();
128 BOOL
performDragOperation();
129 void concludeDragOperation(id sender
);
131 /* If multiple actions are supported by the drag source and
132 the user did not choose a specific action by pressing a
133 modifier key choose a default action to be proposed to
136 sal_Int8
determineDropAction(sal_Int8 dropActions
, id sender
) const;
139 void fire_drop(const com::sun::star::datatransfer::dnd::DropTargetDropEvent
& dte
);
140 void fire_dragEnter(const com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent
& dtdee
);
141 void fire_dragExit(const com::sun::star::datatransfer::dnd::DropTargetEvent
& dte
);
142 void fire_dragOver(const com::sun::star::datatransfer::dnd::DropTargetDragEvent
& dtde
);
143 void fire_dropActionChanged(const com::sun::star::datatransfer::dnd::DropTargetDragEvent
& dtde
);
146 com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetDragContext
> mXCurrentDragContext
;
147 com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetDropContext
> mXCurrentDropContext
;
148 com::sun::star::uno::Reference
< com::sun::star::datatransfer::clipboard::XClipboard
> mXCurrentDragClipboard
;
149 DataFlavorMapperPtr_t mDataFlavorMapper
;
151 AquaSalFrame
* mpFrame
;
152 DropTargetHelper
* mDropTargetHelper
;
154 sal_Int8 mDragSourceSupportedActions
;
155 sal_Int8 mSelectedDropAction
;
156 sal_Int8 mDefaultActions
;
159 #endif // INCLUDED_VCL_OSX_DROPTARGET_HXX
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */