1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> 27cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp> 28cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp> 29cdf0e10cSrcweir #include <rtl/unload.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef COMPHELPER_MAKESEQUENCE_HXX_INCLUDED 32cdf0e10cSrcweir #include "comphelper/makesequence.hxx" 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include "aqua_clipboard.hxx" 37cdf0e10cSrcweir #include "DropTarget.hxx" 38cdf0e10cSrcweir #include "DragActionConversion.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include "DragSource.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <rtl/ustring.h> 43cdf0e10cSrcweir #include <stdio.h> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <premac.h> 46cdf0e10cSrcweir #include <Carbon/Carbon.h> 47cdf0e10cSrcweir #include <postmac.h> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <aqua/salframe.h> 50cdf0e10cSrcweir #include <aqua/salframeview.h> 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace rtl; 53cdf0e10cSrcweir using namespace cppu; 54cdf0e10cSrcweir using namespace osl; 55cdf0e10cSrcweir using namespace com::sun::star::datatransfer; 56cdf0e10cSrcweir using namespace com::sun::star::datatransfer::dnd; 57cdf0e10cSrcweir using namespace com::sun::star::datatransfer::dnd::DNDConstants; 58cdf0e10cSrcweir using namespace com::sun::star::datatransfer::clipboard; 59cdf0e10cSrcweir using namespace com::sun::star::lang; 60cdf0e10cSrcweir using namespace com::sun::star::uno; 61cdf0e10cSrcweir using namespace com::sun::star; 62cdf0e10cSrcweir using namespace comphelper; 63cdf0e10cSrcweir 64cdf0e10cSrcweir OUString dropTarget_getImplementationName() 65cdf0e10cSrcweir { 66cdf0e10cSrcweir return OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1")); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir 70cdf0e10cSrcweir Sequence<OUString> dropTarget_getSupportedServiceNames() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir return makeSequence(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.datatransfer.dnd.OleDropTarget"))); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir 76cdf0e10cSrcweir namespace /* private */ 77cdf0e10cSrcweir { 78cdf0e10cSrcweir // Cocoa's coordinate system has its origin lower-left, VCL's 79cdf0e10cSrcweir // coordinate system upper-left hence we need to transform 80cdf0e10cSrcweir // coordinates 81cdf0e10cSrcweir 82cdf0e10cSrcweir inline void CocoaToVCL(NSPoint& rPoint, const NSRect& bounds) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir rPoint.y = bounds.size.height - rPoint.y; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir inline void CocoaToVCL(NSRect& rRect, const NSRect& bounds) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir rRect.origin.y = bounds.size.height - (rRect.origin.y + rRect.size.height); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir 94cdf0e10cSrcweir @implementation DropTargetHelper 95cdf0e10cSrcweir 96cdf0e10cSrcweir 97cdf0e10cSrcweir -(DropTargetHelper*)initWithDropTarget:(DropTarget*)pdt 98cdf0e10cSrcweir { 99cdf0e10cSrcweir self = [super init]; 100cdf0e10cSrcweir 101cdf0e10cSrcweir if (self) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir mDropTarget = pdt; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir return self; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir 110cdf0e10cSrcweir -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender 111cdf0e10cSrcweir { 112cdf0e10cSrcweir return mDropTarget->draggingEntered(sender); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir 116cdf0e10cSrcweir -(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender 117cdf0e10cSrcweir { 118cdf0e10cSrcweir return mDropTarget->draggingUpdated(sender); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir 122cdf0e10cSrcweir -(void)draggingExited:(id <NSDraggingInfo>)sender 123cdf0e10cSrcweir { 124cdf0e10cSrcweir mDropTarget->draggingExited(sender); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir 128cdf0e10cSrcweir -(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender 129cdf0e10cSrcweir { 130cdf0e10cSrcweir return mDropTarget->prepareForDragOperation(sender); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir 134cdf0e10cSrcweir -(BOOL)performDragOperation:(id <NSDraggingInfo>)sender 135cdf0e10cSrcweir { 136cdf0e10cSrcweir return mDropTarget->performDragOperation(sender); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir 140cdf0e10cSrcweir -(void)concludeDragOperation:(id <NSDraggingInfo>)sender 141cdf0e10cSrcweir { 142cdf0e10cSrcweir mDropTarget->concludeDragOperation(sender); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir 146cdf0e10cSrcweir @end 147cdf0e10cSrcweir 148cdf0e10cSrcweir 149cdf0e10cSrcweir DropTarget::DropTarget() : 150cdf0e10cSrcweir WeakComponentImplHelper5<XInitialization, XDropTarget, XDropTargetDragContext, XDropTargetDropContext, XServiceInfo>(m_aMutex), 151cdf0e10cSrcweir mView(nil), 152cdf0e10cSrcweir mpFrame(NULL), 153cdf0e10cSrcweir mDropTargetHelper(nil), 154cdf0e10cSrcweir mbActive(false), 155cdf0e10cSrcweir mDragSourceSupportedActions(DNDConstants::ACTION_NONE), 156cdf0e10cSrcweir mSelectedDropAction(DNDConstants::ACTION_NONE), 157cdf0e10cSrcweir mDefaultActions(DNDConstants::ACTION_COPY_OR_MOVE | DNDConstants::ACTION_LINK | DNDConstants::ACTION_DEFAULT) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir mDataFlavorMapper = DataFlavorMapperPtr_t(new DataFlavorMapper()); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir 163cdf0e10cSrcweir DropTarget::~DropTarget() 164cdf0e10cSrcweir { 165cdf0e10cSrcweir if( AquaSalFrame::isAlive( mpFrame ) ) 166cdf0e10cSrcweir [(id <DraggingDestinationHandler>)mView unregisterDraggingDestinationHandler:mDropTargetHelper]; 167cdf0e10cSrcweir [mDropTargetHelper release]; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir 171cdf0e10cSrcweir sal_Int8 DropTarget::determineDropAction(sal_Int8 dropActions, id sender) const 172cdf0e10cSrcweir { 173cdf0e10cSrcweir sal_Int8 dropAct = dropActions; 174cdf0e10cSrcweir bool srcAndDestEqual = false; 175cdf0e10cSrcweir 176cdf0e10cSrcweir if ([sender draggingSource] != nil) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir // Internal DnD 179cdf0e10cSrcweir NSView* destView = [[sender draggingDestinationWindow] contentView]; 180cdf0e10cSrcweir srcAndDestEqual = (DragSource::g_DragSourceView == destView); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir // If ACTION_DEFAULT is set this means NSDragOperationGeneric 184cdf0e10cSrcweir // has been set and we map this to ACTION_MOVE or ACTION_COPY 185cdf0e10cSrcweir // depending on whether or not source and dest are equal, 186cdf0e10cSrcweir // this hopefully satisfies all parties 187cdf0e10cSrcweir if( (dropActions == DNDConstants::ACTION_DEFAULT) 188cdf0e10cSrcweir || ((dropActions == mDragSourceSupportedActions) 189cdf0e10cSrcweir && !(~mDragSourceSupportedActions & DNDConstants::ACTION_COPY_OR_MOVE ) ) ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir dropAct = srcAndDestEqual ? DNDConstants::ACTION_MOVE : 192cdf0e10cSrcweir DNDConstants::ACTION_COPY; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir // if more than one drop actions have been specified 195cdf0e10cSrcweir // set ACTION_DEFAULT in order to let the drop target 196cdf0e10cSrcweir // decide which one to use 197cdf0e10cSrcweir else if (dropActions != DNDConstants::ACTION_NONE && 198cdf0e10cSrcweir dropActions != DNDConstants::ACTION_MOVE && 199cdf0e10cSrcweir dropActions != DNDConstants::ACTION_COPY && 200cdf0e10cSrcweir dropActions != DNDConstants::ACTION_LINK) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir if (srcAndDestEqual) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir dropAct = dropActions; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir else // source and destination are different 207cdf0e10cSrcweir { 208cdf0e10cSrcweir if (dropActions & DNDConstants::ACTION_COPY) 209cdf0e10cSrcweir dropAct = DNDConstants::ACTION_COPY; 210cdf0e10cSrcweir else if (dropActions & DNDConstants::ACTION_MOVE) 211cdf0e10cSrcweir dropAct = DNDConstants::ACTION_MOVE; 212cdf0e10cSrcweir else if (dropActions & DNDConstants::ACTION_LINK) 213cdf0e10cSrcweir dropAct = DNDConstants::ACTION_LINK; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir dropAct |= DNDConstants::ACTION_DEFAULT; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir return dropAct; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir 223cdf0e10cSrcweir NSDragOperation DropTarget::draggingEntered(id sender) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir // Initially when DnD will be started no modifier key can be pressed yet 226cdf0e10cSrcweir // thus we are getting all actions that the drag source supports, we save 227cdf0e10cSrcweir // this value because later the system masks the drag source actions if 228cdf0e10cSrcweir // a modifier key will be pressed 229cdf0e10cSrcweir mDragSourceSupportedActions = SystemToOfficeDragActions([sender draggingSourceOperationMask]); 230cdf0e10cSrcweir 231cdf0e10cSrcweir // Only if the drop target is really interessted in the drag actions 232cdf0e10cSrcweir // supported by the source 233cdf0e10cSrcweir if (mDragSourceSupportedActions & mDefaultActions) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir sal_Int8 currentAction = determineDropAction(mDragSourceSupportedActions, sender); 236cdf0e10cSrcweir 237cdf0e10cSrcweir NSRect bounds = [mView bounds]; 238cdf0e10cSrcweir NSPoint dragLocation = [sender draggedImageLocation]; 239cdf0e10cSrcweir 240cdf0e10cSrcweir CocoaToVCL(dragLocation, bounds); 241cdf0e10cSrcweir 242cdf0e10cSrcweir sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x); 243cdf0e10cSrcweir sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y); 244cdf0e10cSrcweir 245cdf0e10cSrcweir NSPasteboard* dragPboard = [sender draggingPasteboard]; 246cdf0e10cSrcweir mXCurrentDragClipboard = new AquaClipboard(dragPboard, false); 247cdf0e10cSrcweir 248cdf0e10cSrcweir uno::Reference<XTransferable> xTransferable = DragSource::g_XTransferable.is() ? 249cdf0e10cSrcweir DragSource::g_XTransferable : mXCurrentDragClipboard->getContents(); 250cdf0e10cSrcweir 251cdf0e10cSrcweir DropTargetDragEnterEvent dtdee(static_cast<OWeakObject*>(this), 252cdf0e10cSrcweir 0, 253cdf0e10cSrcweir this, 254cdf0e10cSrcweir currentAction, 255cdf0e10cSrcweir posX, 256cdf0e10cSrcweir posY, 257cdf0e10cSrcweir mDragSourceSupportedActions, 258cdf0e10cSrcweir xTransferable->getTransferDataFlavors()); 259cdf0e10cSrcweir 260cdf0e10cSrcweir fire_dragEnter(dtdee); 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir return OfficeToSystemDragActions(mSelectedDropAction); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir 267cdf0e10cSrcweir NSDragOperation DropTarget::draggingUpdated(id sender) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir sal_Int8 currentDragSourceActions = 270cdf0e10cSrcweir SystemToOfficeDragActions([sender draggingSourceOperationMask]); 271cdf0e10cSrcweir NSDragOperation dragOp = NSDragOperationNone; 272cdf0e10cSrcweir 273cdf0e10cSrcweir if (currentDragSourceActions & mDefaultActions) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir sal_Int8 currentAction = determineDropAction(currentDragSourceActions, sender); 276cdf0e10cSrcweir NSRect bounds = [mView bounds]; 277cdf0e10cSrcweir NSPoint dragLocation = [sender draggedImageLocation]; 278cdf0e10cSrcweir 279cdf0e10cSrcweir CocoaToVCL(dragLocation, bounds); 280cdf0e10cSrcweir 281cdf0e10cSrcweir sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x); 282cdf0e10cSrcweir sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y); 283cdf0e10cSrcweir 284cdf0e10cSrcweir DropTargetDragEvent dtde(static_cast<OWeakObject*>(this), 285cdf0e10cSrcweir 0, 286cdf0e10cSrcweir this, 287cdf0e10cSrcweir currentAction, 288cdf0e10cSrcweir posX, 289cdf0e10cSrcweir posY, 290cdf0e10cSrcweir mDragSourceSupportedActions); 291cdf0e10cSrcweir 292cdf0e10cSrcweir fire_dragOver(dtde); 293cdf0e10cSrcweir 294cdf0e10cSrcweir // drag over callbacks likely have rendered something 295cdf0e10cSrcweir [mView setNeedsDisplay: TRUE]; 296cdf0e10cSrcweir 297cdf0e10cSrcweir dragOp = OfficeToSystemDragActions(mSelectedDropAction); 298cdf0e10cSrcweir 299cdf0e10cSrcweir //NSLog(@"Drag update: Source actions: %x proposed action %x selected action %x", mDragSourceSupportedActions, currentAction, mSelectedDropAction); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir // Weird but it appears as if there is no method in Cocoa 303cdf0e10cSrcweir // to create a kThemeCopyArrowCursor hence we have to use 304cdf0e10cSrcweir // Carbon to do it 305cdf0e10cSrcweir if (dragOp == NSDragOperationNone) 306cdf0e10cSrcweir SetThemeCursor(kThemeNotAllowedCursor); 307cdf0e10cSrcweir else if (dragOp == NSDragOperationCopy) 308cdf0e10cSrcweir SetThemeCursor(kThemeCopyArrowCursor); 309cdf0e10cSrcweir else 310cdf0e10cSrcweir SetThemeCursor(kThemeArrowCursor); 311cdf0e10cSrcweir 312cdf0e10cSrcweir return dragOp; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir 316cdf0e10cSrcweir void DropTarget::draggingExited(id /*sender*/) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir DropTargetEvent dte(static_cast<OWeakObject*>(this), 0); 319cdf0e10cSrcweir fire_dragExit(dte); 320cdf0e10cSrcweir mDragSourceSupportedActions = DNDConstants::ACTION_NONE; 321cdf0e10cSrcweir mSelectedDropAction = DNDConstants::ACTION_NONE; 322cdf0e10cSrcweir SetThemeCursor(kThemeArrowCursor); 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir 326cdf0e10cSrcweir BOOL DropTarget::prepareForDragOperation(id /*sender*/) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir return 1; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir 332cdf0e10cSrcweir BOOL DropTarget::performDragOperation(id sender) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir bool bSuccess = false; 335cdf0e10cSrcweir 336cdf0e10cSrcweir if (mSelectedDropAction != DNDConstants::ACTION_NONE) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir uno::Reference<XTransferable> xTransferable = DragSource::g_XTransferable; 339cdf0e10cSrcweir 340cdf0e10cSrcweir if (!DragSource::g_XTransferable.is()) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir xTransferable = mXCurrentDragClipboard->getContents(); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir NSRect bounds = [mView bounds]; 346cdf0e10cSrcweir NSPoint dragLocation = [sender draggedImageLocation]; 347cdf0e10cSrcweir 348cdf0e10cSrcweir CocoaToVCL(dragLocation, bounds); 349cdf0e10cSrcweir 350cdf0e10cSrcweir sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x); 351cdf0e10cSrcweir sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y); 352cdf0e10cSrcweir 353cdf0e10cSrcweir DropTargetDropEvent dtde(static_cast<OWeakObject*>(this), 354cdf0e10cSrcweir 0, 355cdf0e10cSrcweir this, 356cdf0e10cSrcweir mSelectedDropAction, 357cdf0e10cSrcweir posX, 358cdf0e10cSrcweir posY, 359cdf0e10cSrcweir mDragSourceSupportedActions, 360cdf0e10cSrcweir xTransferable); 361cdf0e10cSrcweir 362cdf0e10cSrcweir fire_drop(dtde); 363cdf0e10cSrcweir 364cdf0e10cSrcweir bSuccess = true; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir return bSuccess; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir 371cdf0e10cSrcweir void DropTarget::concludeDragOperation(id /*sender*/) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir mDragSourceSupportedActions = DNDConstants::ACTION_NONE; 374cdf0e10cSrcweir mSelectedDropAction = DNDConstants::ACTION_NONE; 375cdf0e10cSrcweir mXCurrentDragClipboard = uno::Reference<XClipboard>(); 376cdf0e10cSrcweir SetThemeCursor(kThemeArrowCursor); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir 380cdf0e10cSrcweir // called from WeakComponentImplHelperX::dispose 381cdf0e10cSrcweir // WeakComponentImplHelper calls disposing before it destroys 382cdf0e10cSrcweir // itself. 383cdf0e10cSrcweir void SAL_CALL DropTarget::disposing() 384cdf0e10cSrcweir { 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir 388cdf0e10cSrcweir void SAL_CALL DropTarget::initialize(const Sequence< Any >& aArguments) 389cdf0e10cSrcweir throw(Exception) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir if (aArguments.getLength() < 2) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM("DropTarget::initialize: Cannot install window event handler")), 394cdf0e10cSrcweir static_cast<OWeakObject*>(this)); 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir Any pNSView = aArguments[0]; 398cdf0e10cSrcweir sal_uInt64 tmp = 0; 399cdf0e10cSrcweir pNSView >>= tmp; 400cdf0e10cSrcweir mView = (id)tmp; 401cdf0e10cSrcweir mpFrame = [(SalFrameView*)mView getSalFrame]; 402cdf0e10cSrcweir 403cdf0e10cSrcweir mDropTargetHelper = [[DropTargetHelper alloc] initWithDropTarget: this]; 404cdf0e10cSrcweir 405cdf0e10cSrcweir [(id <DraggingDestinationHandler>)mView registerDraggingDestinationHandler:mDropTargetHelper]; 406cdf0e10cSrcweir [mView registerForDraggedTypes: mDataFlavorMapper->getAllSupportedPboardTypes()]; 407cdf0e10cSrcweir 408cdf0e10cSrcweir id wnd = [mView window]; 409cdf0e10cSrcweir NSWindow* parentWnd = [wnd parentWindow]; 410cdf0e10cSrcweir unsigned int topWndStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask); 411cdf0e10cSrcweir unsigned int wndStyles = [wnd styleMask] & topWndStyle; 412cdf0e10cSrcweir 413cdf0e10cSrcweir if (parentWnd == nil && (wndStyles == topWndStyle)) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir [wnd registerDraggingDestinationHandler:mDropTargetHelper]; 416cdf0e10cSrcweir [wnd registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir } 419cdf0e10cSrcweir 420cdf0e10cSrcweir 421cdf0e10cSrcweir void SAL_CALL DropTarget::addDropTargetListener(const uno::Reference<XDropTargetListener>& dtl) 422cdf0e10cSrcweir throw(RuntimeException) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir rBHelper.addListener(::getCppuType(&dtl), dtl); 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir 428cdf0e10cSrcweir void SAL_CALL DropTarget::removeDropTargetListener(const uno::Reference<XDropTargetListener>& dtl) 429cdf0e10cSrcweir throw(RuntimeException) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir rBHelper.removeListener(::getCppuType(&dtl), dtl); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir 434cdf0e10cSrcweir 435cdf0e10cSrcweir sal_Bool SAL_CALL DropTarget::isActive( ) throw(RuntimeException) 436cdf0e10cSrcweir { 437cdf0e10cSrcweir return mbActive; 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440cdf0e10cSrcweir 441cdf0e10cSrcweir void SAL_CALL DropTarget::setActive(sal_Bool active) throw(RuntimeException) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir mbActive = active; 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir 447cdf0e10cSrcweir sal_Int8 SAL_CALL DropTarget::getDefaultActions() throw(RuntimeException) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir return mDefaultActions; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir 453cdf0e10cSrcweir void SAL_CALL DropTarget::setDefaultActions(sal_Int8 actions) throw(RuntimeException) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir OSL_ENSURE( actions < 8, "No valid default actions"); 456cdf0e10cSrcweir mDefaultActions= actions; 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir 460cdf0e10cSrcweir // XDropTargetDragContext 461cdf0e10cSrcweir 462cdf0e10cSrcweir void SAL_CALL DropTarget::acceptDrag(sal_Int8 dragOperation) throw (RuntimeException) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir mSelectedDropAction = dragOperation; 465cdf0e10cSrcweir } 466cdf0e10cSrcweir 467cdf0e10cSrcweir 468cdf0e10cSrcweir void SAL_CALL DropTarget::rejectDrag() throw (RuntimeException) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir mSelectedDropAction = DNDConstants::ACTION_NONE; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir 474cdf0e10cSrcweir //XDropTargetDropContext 475cdf0e10cSrcweir 476cdf0e10cSrcweir void SAL_CALL DropTarget::acceptDrop(sal_Int8 dropOperation) throw( RuntimeException) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir mSelectedDropAction = dropOperation; 479cdf0e10cSrcweir } 480cdf0e10cSrcweir 481cdf0e10cSrcweir 482cdf0e10cSrcweir void SAL_CALL DropTarget::rejectDrop() throw (RuntimeException) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir mSelectedDropAction = DNDConstants::ACTION_NONE; 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir 488cdf0e10cSrcweir void SAL_CALL DropTarget::dropComplete(sal_Bool success) throw (RuntimeException) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir // Reset the internal transferable used as shortcut in case this is 491cdf0e10cSrcweir // an internal D&D operation 492cdf0e10cSrcweir DragSource::g_XTransferable = uno::Reference<XTransferable>(); 493cdf0e10cSrcweir DragSource::g_DropSuccessSet = true; 494cdf0e10cSrcweir DragSource::g_DropSuccess = success; 495cdf0e10cSrcweir } 496cdf0e10cSrcweir 497cdf0e10cSrcweir 498cdf0e10cSrcweir void DropTarget::fire_drop( const DropTargetDropEvent& dte) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) ); 501cdf0e10cSrcweir if( pContainer) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir OInterfaceIteratorHelper iter( *pContainer); 504cdf0e10cSrcweir while( iter.hasMoreElements()) 505cdf0e10cSrcweir { 506cdf0e10cSrcweir uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); 507cdf0e10cSrcweir 508cdf0e10cSrcweir try { listener->drop( dte); } 509cdf0e10cSrcweir catch(RuntimeException&) {} 510cdf0e10cSrcweir } 511cdf0e10cSrcweir } 512cdf0e10cSrcweir } 513cdf0e10cSrcweir 514cdf0e10cSrcweir 515cdf0e10cSrcweir void DropTarget::fire_dragEnter(const DropTargetDragEnterEvent& e) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) ); 518cdf0e10cSrcweir if( pContainer) 519cdf0e10cSrcweir { 520cdf0e10cSrcweir OInterfaceIteratorHelper iter( *pContainer); 521cdf0e10cSrcweir while( iter.hasMoreElements()) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); 524cdf0e10cSrcweir 525cdf0e10cSrcweir try { listener->dragEnter( e); } 526cdf0e10cSrcweir catch (RuntimeException&) {} 527cdf0e10cSrcweir } 528cdf0e10cSrcweir } 529cdf0e10cSrcweir } 530cdf0e10cSrcweir 531cdf0e10cSrcweir 532cdf0e10cSrcweir void DropTarget::fire_dragExit(const DropTargetEvent& dte) 533cdf0e10cSrcweir { 534cdf0e10cSrcweir OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) ); 535cdf0e10cSrcweir 536cdf0e10cSrcweir if( pContainer) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir OInterfaceIteratorHelper iter( *pContainer); 539cdf0e10cSrcweir while( iter.hasMoreElements()) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); 542cdf0e10cSrcweir 543cdf0e10cSrcweir try { listener->dragExit( dte); } 544cdf0e10cSrcweir catch (RuntimeException&) {} 545cdf0e10cSrcweir } 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir 550cdf0e10cSrcweir void DropTarget::fire_dragOver(const DropTargetDragEvent& dtde) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) ); 553cdf0e10cSrcweir if( pContainer) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir OInterfaceIteratorHelper iter( *pContainer ); 556cdf0e10cSrcweir while( iter.hasMoreElements()) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); 559cdf0e10cSrcweir 560cdf0e10cSrcweir try { listener->dragOver( dtde); } 561cdf0e10cSrcweir catch (RuntimeException&) {} 562cdf0e10cSrcweir } 563cdf0e10cSrcweir } 564cdf0e10cSrcweir } 565cdf0e10cSrcweir 566cdf0e10cSrcweir 567cdf0e10cSrcweir void DropTarget::fire_dropActionChanged(const DropTargetDragEvent& dtde) 568cdf0e10cSrcweir { 569cdf0e10cSrcweir OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) ); 570cdf0e10cSrcweir if( pContainer) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir OInterfaceIteratorHelper iter( *pContainer); 573cdf0e10cSrcweir while( iter.hasMoreElements()) 574cdf0e10cSrcweir { 575cdf0e10cSrcweir uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); 576cdf0e10cSrcweir 577cdf0e10cSrcweir try { listener->dropActionChanged( dtde); } 578cdf0e10cSrcweir catch (RuntimeException&) {} 579cdf0e10cSrcweir } 580cdf0e10cSrcweir } 581cdf0e10cSrcweir } 582cdf0e10cSrcweir 583cdf0e10cSrcweir 584cdf0e10cSrcweir // XServiceInfo 585cdf0e10cSrcweir 586cdf0e10cSrcweir OUString SAL_CALL DropTarget::getImplementationName() throw (RuntimeException) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir return dropTarget_getImplementationName(); 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir 592cdf0e10cSrcweir sal_Bool SAL_CALL DropTarget::supportsService( const OUString& ServiceName ) throw (RuntimeException) 593cdf0e10cSrcweir { 594cdf0e10cSrcweir return ServiceName.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.datatransfer.dnd.OleDropTarget"))); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir 598cdf0e10cSrcweir Sequence< OUString > SAL_CALL DropTarget::getSupportedServiceNames( ) throw (RuntimeException) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir return dropTarget_getSupportedServiceNames(); 601cdf0e10cSrcweir } 602cdf0e10cSrcweir 603