Add DND move support on OS X
The drag mask passed by Cocoa is conservative and doesn't include NSDragOperationMove which was added later. Override draggingSourceOperationMaskForLocal to include that flag if it's wanted. This also moving of text the default behaviour. Closes #13819. Closes #14726.
This commit is contained in:
@@ -56,11 +56,15 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
|
|||||||
BOOL dragFinished;
|
BOOL dragFinished;
|
||||||
int resultCode;
|
int resultCode;
|
||||||
wxDropSource* impl;
|
wxDropSource* impl;
|
||||||
|
|
||||||
|
// Flags for drag and drop operations (wxDrag_* ).
|
||||||
|
int m_dragFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImplementation: (wxDropSource *)dropSource;
|
- (void)setImplementation:(wxDropSource *)dropSource flags:(int)flags;
|
||||||
- (BOOL)finished;
|
- (BOOL)finished;
|
||||||
- (NSDragOperation)code;
|
- (NSDragOperation)code;
|
||||||
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)forLocal;
|
||||||
- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint;
|
- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint;
|
||||||
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
|
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
|
||||||
@end
|
@end
|
||||||
@@ -73,12 +77,14 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
|
|||||||
dragFinished = NO;
|
dragFinished = NO;
|
||||||
resultCode = NSDragOperationNone;
|
resultCode = NSDragOperationNone;
|
||||||
impl = 0;
|
impl = 0;
|
||||||
|
m_dragFlags = wxDrag_CopyOnly;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImplementation: (wxDropSource *)dropSource
|
- (void)setImplementation:(wxDropSource *)dropSource flags:(int)flags
|
||||||
{
|
{
|
||||||
impl = dropSource;
|
impl = dropSource;
|
||||||
|
m_dragFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)finished
|
- (BOOL)finished
|
||||||
@@ -91,6 +97,31 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
|
|||||||
return resultCode;
|
return resultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)forLocal
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
By default drag targets receive a mask of NSDragOperationAll (0xf)
|
||||||
|
which, despite its name, does not include the later added
|
||||||
|
NSDragOperationMove (0x10) that sometimes is wanted.
|
||||||
|
Use NSDragOperationEvery instead because it includes all flags.
|
||||||
|
|
||||||
|
Note that this, compared to the previous behaviour, adds
|
||||||
|
NSDragOperationDelete to the mask which seems harmless.
|
||||||
|
|
||||||
|
We are also keeping NSDragOperationLink and NSDragOperationPrivate
|
||||||
|
in to preserve previous behaviour.
|
||||||
|
*/
|
||||||
|
|
||||||
|
NSDragOperation allowedDragOperations = NSDragOperationEvery;
|
||||||
|
|
||||||
|
if (m_dragFlags == wxDrag_CopyOnly)
|
||||||
|
{
|
||||||
|
allowedDragOperations &= ~NSDragOperationMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
return allowedDragOperations;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint
|
- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint
|
||||||
{
|
{
|
||||||
wxUnusedVar( anImage );
|
wxUnusedVar( anImage );
|
||||||
@@ -186,7 +217,7 @@ wxDropSource* wxDropSource::GetCurrentDropSource()
|
|||||||
return gCurrentSource;
|
return gCurrentSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
|
wxDragResult wxDropSource::DoDragDrop(int flags)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
|
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
|
||||||
|
|
||||||
@@ -240,7 +271,7 @@ wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
|
|||||||
|
|
||||||
|
|
||||||
DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
|
DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
|
||||||
[delegate setImplementation: this];
|
[delegate setImplementation:this flags:flags];
|
||||||
[view dragImage:image at:p offset:NSMakeSize(0.0,0.0)
|
[view dragImage:image at:p offset:NSMakeSize(0.0,0.0)
|
||||||
event: theEvent pasteboard: pboard source:delegate slideBack: NO];
|
event: theEvent pasteboard: pboard source:delegate slideBack: NO];
|
||||||
|
|
||||||
|
@@ -1210,6 +1210,11 @@ unsigned int wxOnDraggingEnteredOrUpdated(wxWidgetCocoaImpl* viewImpl,
|
|||||||
sourceDragMask contains copy, link, generic, and private flags. Formerly
|
sourceDragMask contains copy, link, generic, and private flags. Formerly
|
||||||
this would result in wxDragLink which is not what is expected for text.
|
this would result in wxDragLink which is not what is expected for text.
|
||||||
Give precedence to the move and copy flag instead.
|
Give precedence to the move and copy flag instead.
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
In order to respect wxDrag_DefaultMove, access to dnd.mm's
|
||||||
|
DropSourceDelegate will be needed which contains the wxDrag value used.
|
||||||
|
(The draggingSource method of sender points to a DropSourceDelegate* ).
|
||||||
*/
|
*/
|
||||||
wxDragResult result = wxDragNone;
|
wxDragResult result = wxDragNone;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user