1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DropTarget.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DROPTARGET_HXX_
32 #define _DROPTARGET_HXX_
34 #include "DataFlavorMapping.hxx"
35 #include <cppuhelper/compbase5.hxx>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
39 #ifndef _COM_SUN_STAR_DATATRANSFER_DND_XDROPTARGETLISTENR_HPP_
40 #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp>
42 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
43 #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
44 #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp>
45 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <cppuhelper/basemutex.hxx>
48 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
50 #include <boost/utility.hpp>
53 #import <Cocoa/Cocoa.h>
58 /* The functions declared in this protocol are actually
59 declared in vcl/aqua/inc/salframe.h. Because we want
60 to avoid importing VCL headers in UNO services and
61 on the other hand want to avoid warnings caused by
62 gcc complaining about unknowness of these functions
63 we declare them in a protocol here and cast at the
66 @protocol DraggingDestinationHandler
67 -(void)registerDraggingDestinationHandler
:(id
)theHandler
;
68 -(void)unregisterDraggingDestinationHandler
:(id
)theHandler
;
72 @interface DropTargetHelper
: NSObject
74 DropTarget
* mDropTarget
;
77 -(DropTargetHelper
*)initWithDropTarget
:(DropTarget
*)pdt
;
79 -(NSDragOperation
)draggingEntered
:(id
<NSDraggingInfo
>)sender
;
80 -(NSDragOperation
)draggingUpdated
:(id
<NSDraggingInfo
>)sender
;
81 -(void)draggingExited
:(id
<NSDraggingInfo
>)sender
;
82 -(MacOSBOOL
)prepareForDragOperation
:(id
<NSDraggingInfo
>)sender
;
83 -(MacOSBOOL
)performDragOperation
:(id
<NSDraggingInfo
>)sender
;
84 -(void)concludeDragOperation
:(id
<NSDraggingInfo
>)sender
;
89 class DropTarget
: public cppu::BaseMutex
,
90 public cppu::WeakComponentImplHelper5
< com::sun::star::lang::XInitialization
,
91 com::sun::star::datatransfer::dnd::XDropTarget
,
92 com::sun::star::datatransfer::dnd::XDropTargetDragContext
,
93 com::sun::star::datatransfer::dnd::XDropTargetDropContext
,
94 com::sun::star::lang::XServiceInfo
>,
95 private boost::noncopyable
99 virtual ~DropTarget();
101 // Overrides WeakComponentImplHelper::disposing which is called by
102 // WeakComponentImplHelper::dispose
104 virtual void SAL_CALL
disposing();
107 virtual void SAL_CALL
initialize( const com::sun::star::uno::Sequence
< com::sun::star::uno::Any
>& aArguments
)
108 throw(com::sun::star::uno::Exception
);
111 virtual void SAL_CALL
addDropTargetListener( const com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetListener
>& dtl
)
112 throw(com::sun::star::uno::RuntimeException
);
114 virtual void SAL_CALL
removeDropTargetListener( const com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetListener
>& dtl
)
115 throw(com::sun::star::uno::RuntimeException
);
117 // Default is not active
118 virtual sal_Bool SAL_CALL
isActive() throw(com::sun::star::uno::RuntimeException
);
119 virtual void SAL_CALL
setActive(sal_Bool isActive
) throw(com::sun::star::uno::RuntimeException
);
120 virtual sal_Int8 SAL_CALL
getDefaultActions() throw(com::sun::star::uno::RuntimeException
);
121 virtual void SAL_CALL
setDefaultActions(sal_Int8 actions
) throw(com::sun::star::uno::RuntimeException
);
123 // XDropTargetDragContext
124 virtual void SAL_CALL
acceptDrag(sal_Int8 dragOperation
) throw(com::sun::star::uno::RuntimeException
);
125 virtual void SAL_CALL
rejectDrag() throw(com::sun::star::uno::RuntimeException
);
127 // XDropTargetDragContext
128 virtual void SAL_CALL
acceptDrop(sal_Int8 dropOperation
) throw (com::sun::star::uno::RuntimeException
);
129 virtual void SAL_CALL
rejectDrop() throw (com::sun::star::uno::RuntimeException
);
130 virtual void SAL_CALL
dropComplete(sal_Bool success
) throw (com::sun::star::uno::RuntimeException
);
133 virtual rtl::OUString SAL_CALL
getImplementationName() throw (com::sun::star::uno::RuntimeException
);
134 virtual sal_Bool SAL_CALL
supportsService(const rtl::OUString
& ServiceName
) throw (com::sun::star::uno::RuntimeException
);
135 virtual com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException
);
137 // NSDraggingDestination protocol functions
138 virtual NSDragOperation
draggingEntered(id sender
);
139 virtual NSDragOperation
draggingUpdated(id sender
);
140 virtual void draggingExited(id sender
);
141 virtual MacOSBOOL
prepareForDragOperation(id sender
);
142 virtual MacOSBOOL
performDragOperation(id sender
);
143 virtual void concludeDragOperation(id sender
);
145 /* If multiple actions are supported by the drag source and
146 the user did not choose a specific action by pressing a
147 modifier key choose a default action to be proposed to
150 sal_Int8
determineDropAction(sal_Int8 dropActions
, id sender
) const;
153 void fire_drop(const com::sun::star::datatransfer::dnd::DropTargetDropEvent
& dte
);
154 void fire_dragEnter(const com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent
& dtdee
);
155 void fire_dragExit(const com::sun::star::datatransfer::dnd::DropTargetEvent
& dte
);
156 void fire_dragOver(const com::sun::star::datatransfer::dnd::DropTargetDragEvent
& dtde
);
157 void fire_dropActionChanged(const com::sun::star::datatransfer::dnd::DropTargetDragEvent
& dtde
);
160 com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetDragContext
> mXCurrentDragContext
;
161 com::sun::star::uno::Reference
< com::sun::star::datatransfer::dnd::XDropTargetDropContext
> mXCurrentDropContext
;
162 com::sun::star::uno::Reference
< com::sun::star::datatransfer::clipboard::XClipboard
> mXCurrentDragClipboard
;
163 DataFlavorMapperPtr_t mDataFlavorMapper
;
165 DropTargetHelper
* mDropTargetHelper
;
167 sal_Int8 mDragSourceSupportedActions
;
168 sal_Int8 mSelectedDropAction
;
169 sal_Int8 mDefaultActions
;