Refactor some DND code in wxOSX/Cocoa
To reduce duplication of the same changes, merge the nearly identical wxWidgetCocoaImpl::draggingEntered and draggingUpdated into private function wxOnDraggingEnteredOrUpdated.
This commit is contained in:
@@ -1164,13 +1164,18 @@ void wxOSX_controlDoubleAction(NSView* self, SEL _cmd, id sender)
|
||||
}
|
||||
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
unsigned int wxOnDraggingEnteredOrUpdated(wxWidgetCocoaImpl* viewImpl,
|
||||
void *s, bool entered)
|
||||
{
|
||||
id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
||||
|
||||
wxWindow* wxpeer = GetWXPeer();
|
||||
wxWindow* wxpeer = viewImpl->GetWXPeer();
|
||||
if ( wxpeer == NULL )
|
||||
return NSDragOperationNone;
|
||||
|
||||
@@ -1179,8 +1184,8 @@ unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf),
|
||||
return NSDragOperationNone;
|
||||
|
||||
wxDragResult result = wxDragNone;
|
||||
NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
|
||||
wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
|
||||
NSPoint nspoint = [viewImpl->GetWXWidget() convertPoint:[sender draggingLocation] fromView:nil];
|
||||
wxPoint pt = wxFromNSPoint( viewImpl->GetWXWidget(), nspoint );
|
||||
|
||||
if ( sourceDragMask & NSDragOperationLink )
|
||||
result = wxDragLink;
|
||||
@@ -1192,7 +1197,17 @@ unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf),
|
||||
PasteboardRef pboardRef;
|
||||
PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
|
||||
target->SetCurrentDragPasteboard(pboardRef);
|
||||
result = target->OnEnter(pt.x, pt.y, result);
|
||||
if (entered)
|
||||
{
|
||||
// Drag entered
|
||||
result = target->OnEnter(pt.x, pt.y, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Drag updated
|
||||
result = target->OnDragOver(pt.x, pt.y, result);
|
||||
}
|
||||
|
||||
CFRelease(pboardRef);
|
||||
|
||||
NSDragOperation nsresult = NSDragOperationNone;
|
||||
@@ -1210,6 +1225,13 @@ unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf),
|
||||
return nsresult;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
|
||||
{
|
||||
return wxOnDraggingEnteredOrUpdated(this, s, true /*entered*/);
|
||||
}
|
||||
|
||||
void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
|
||||
{
|
||||
id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
|
||||
@@ -1232,48 +1254,7 @@ void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget WXUNUSED(slf), void *WX
|
||||
|
||||
unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
|
||||
{
|
||||
id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
|
||||
NSPasteboard *pboard = [sender draggingPasteboard];
|
||||
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
||||
|
||||
wxWindow* wxpeer = GetWXPeer();
|
||||
if ( wxpeer == NULL )
|
||||
return NSDragOperationNone;
|
||||
|
||||
wxDropTarget* target = wxpeer->GetDropTarget();
|
||||
if ( target == NULL )
|
||||
return NSDragOperationNone;
|
||||
|
||||
wxDragResult result = wxDragNone;
|
||||
NSPoint nspoint = [m_osxView convertPoint:[sender draggingLocation] fromView:nil];
|
||||
wxPoint pt = wxFromNSPoint( m_osxView, nspoint );
|
||||
|
||||
if ( sourceDragMask & NSDragOperationLink )
|
||||
result = wxDragLink;
|
||||
else if ( sourceDragMask & NSDragOperationCopy )
|
||||
result = wxDragCopy;
|
||||
else if ( sourceDragMask & NSDragOperationMove )
|
||||
result = wxDragMove;
|
||||
|
||||
PasteboardRef pboardRef;
|
||||
PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
|
||||
target->SetCurrentDragPasteboard(pboardRef);
|
||||
result = target->OnDragOver(pt.x, pt.y, result);
|
||||
CFRelease(pboardRef);
|
||||
|
||||
NSDragOperation nsresult = NSDragOperationNone;
|
||||
switch (result )
|
||||
{
|
||||
case wxDragLink:
|
||||
nsresult = NSDragOperationLink;
|
||||
case wxDragMove:
|
||||
nsresult = NSDragOperationMove;
|
||||
case wxDragCopy:
|
||||
nsresult = NSDragOperationCopy;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return nsresult;
|
||||
return wxOnDraggingEnteredOrUpdated(this, s, false /*updated*/);
|
||||
}
|
||||
|
||||
bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd))
|
||||
|
Reference in New Issue
Block a user