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