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 _DROPTARGET_HXX_ 25 #define _DROPTARGET_HXX_ 26 27 #include "DataFlavorMapping.hxx" 28 #include <cppuhelper/compbase5.hxx> 29 #include <com/sun/star/lang/XInitialization.hpp> 30 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> 31 32 #ifndef _COM_SUN_STAR_DATATRANSFER_DND_XDROPTARGETLISTENR_HPP_ 33 #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp> 34 #endif 35 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp> 36 #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp> 37 #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp> 38 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 39 #include <com/sun/star/lang/XServiceInfo.hpp> 40 #include <cppuhelper/basemutex.hxx> 41 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 42 43 #include <boost/utility.hpp> 44 45 #include <premac.h> 46 #import <Cocoa/Cocoa.h> 47 #include <postmac.h> 48 49 class DropTarget; 50 class AquaSalFrame; 51 52 /* The functions declared in this protocol are actually 53 declared in vcl/aqua/inc/salframe.h. Because we want 54 to avoid importing VCL headers in UNO services and 55 on the other hand want to avoid warnings caused by 56 gcc complaining about unknowness of these functions 57 we declare them in a protocol here and cast at the 58 appropriate places. 59 */ 60 @protocol DraggingDestinationHandler 61 -(void)registerDraggingDestinationHandler:(id)theHandler; 62 -(void)unregisterDraggingDestinationHandler:(id)theHandler; 63 @end 64 65 66 @interface DropTargetHelper : NSObject 67 { 68 DropTarget* mDropTarget; 69 } 70 71 -(DropTargetHelper*)initWithDropTarget:(DropTarget*)pdt; 72 73 -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender; 74 -(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender; 75 -(void)draggingExited:(id <NSDraggingInfo>)sender; 76 -(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender; 77 -(BOOL)performDragOperation:(id <NSDraggingInfo>)sender; 78 -(void)concludeDragOperation:(id <NSDraggingInfo>)sender; 79 80 @end 81 82 83 class DropTarget: public cppu::BaseMutex, 84 public cppu::WeakComponentImplHelper5< com::sun::star::lang::XInitialization, 85 com::sun::star::datatransfer::dnd::XDropTarget, 86 com::sun::star::datatransfer::dnd::XDropTargetDragContext, 87 com::sun::star::datatransfer::dnd::XDropTargetDropContext, 88 com::sun::star::lang::XServiceInfo >, 89 private boost::noncopyable 90 { 91 public: 92 DropTarget(); 93 virtual ~DropTarget(); 94 95 // Overrides WeakComponentImplHelper::disposing which is called by 96 // WeakComponentImplHelper::dispose 97 // Must be called. 98 virtual void SAL_CALL disposing(); 99 100 // XInitialization 101 virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments ); 102 103 // XDropTarget 104 virtual void SAL_CALL addDropTargetListener( const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetListener >& dtl ); 105 106 virtual void SAL_CALL removeDropTargetListener( const com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetListener >& dtl ); 107 108 // Default is not active 109 virtual sal_Bool SAL_CALL isActive(); 110 virtual void SAL_CALL setActive(sal_Bool isActive); 111 virtual sal_Int8 SAL_CALL getDefaultActions(); 112 virtual void SAL_CALL setDefaultActions(sal_Int8 actions); 113 114 // XDropTargetDragContext 115 virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation); 116 virtual void SAL_CALL rejectDrag(); 117 118 // XDropTargetDragContext 119 virtual void SAL_CALL acceptDrop(sal_Int8 dropOperation); 120 virtual void SAL_CALL rejectDrop(); 121 virtual void SAL_CALL dropComplete(sal_Bool success); 122 123 // XServiceInfo 124 virtual rtl::OUString SAL_CALL getImplementationName(); 125 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName); 126 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(); 127 128 // NSDraggingDestination protocol functions 129 virtual NSDragOperation draggingEntered(id sender); 130 virtual NSDragOperation draggingUpdated(id sender); 131 virtual void draggingExited(id sender); 132 virtual BOOL prepareForDragOperation(id sender); 133 virtual BOOL performDragOperation(); 134 virtual void concludeDragOperation(id sender); 135 136 /* If multiple actions are supported by the drag source and 137 the user did not choose a specific action by pressing a 138 modifier key choose a default action to be proposed to 139 the application. 140 */ 141 sal_Int8 determineDropAction(sal_Int8 dropActions, id sender) const; 142 143 private: 144 void fire_drop(const com::sun::star::datatransfer::dnd::DropTargetDropEvent& dte); 145 void fire_dragEnter(const com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee); 146 void fire_dragExit(const com::sun::star::datatransfer::dnd::DropTargetEvent& dte); 147 void fire_dragOver(const com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde); 148 void fire_dropActionChanged(const com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde); 149 150 private: 151 com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetDragContext > mXCurrentDragContext; 152 com::sun::star::uno::Reference< com::sun::star::datatransfer::dnd::XDropTargetDropContext > mXCurrentDropContext; 153 com::sun::star::uno::Reference< com::sun::star::datatransfer::clipboard::XClipboard > mXCurrentDragClipboard; 154 DataFlavorMapperPtr_t mDataFlavorMapper; 155 id mView; 156 AquaSalFrame* mpFrame; 157 DropTargetHelper* mDropTargetHelper; 158 bool mbActive; 159 sal_Int8 mDragSourceSupportedActions; 160 sal_Int8 mSelectedDropAction; 161 sal_Int8 mDefaultActions; 162 }; 163 164 #endif 165