storing current event for dnd support, adding default data-drag image, fixes #12065
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64663 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -87,6 +87,9 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
|
|||||||
|
|
||||||
- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint
|
- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint
|
||||||
{
|
{
|
||||||
|
wxUnusedVar( anImage );
|
||||||
|
wxUnusedVar( aPoint );
|
||||||
|
|
||||||
bool optionDown = GetCurrentKeyModifiers() & optionKey;
|
bool optionDown = GetCurrentKeyModifiers() & optionKey;
|
||||||
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
|
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
|
||||||
|
|
||||||
@@ -120,8 +123,12 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
|
|||||||
|
|
||||||
if (cursorID != wxCURSOR_NONE)
|
if (cursorID != wxCURSOR_NONE)
|
||||||
{
|
{
|
||||||
|
// TODO under 10.6 the os itself deals with the cursor, remove if things
|
||||||
|
// work properly everywhere
|
||||||
|
#if 0
|
||||||
wxCursor cursor( cursorID );
|
wxCursor cursor( cursorID );
|
||||||
cursor.MacInstall();
|
cursor.MacInstall();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,6 +136,9 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
|
|||||||
|
|
||||||
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
|
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
|
||||||
{
|
{
|
||||||
|
wxUnusedVar( anImage );
|
||||||
|
wxUnusedVar( aPoint );
|
||||||
|
|
||||||
resultCode = operation;
|
resultCode = operation;
|
||||||
dragFinished = YES;
|
dragFinished = YES;
|
||||||
}
|
}
|
||||||
@@ -170,7 +180,7 @@ wxDropSource* wxDropSource::GetCurrentDropSource()
|
|||||||
return gCurrentSource;
|
return gCurrentSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDragResult wxDropSource::DoDragDrop(int flags)
|
wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
|
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
|
||||||
|
|
||||||
@@ -201,12 +211,31 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
|
|||||||
|
|
||||||
NSEvent* theEvent = (NSEvent*)wxTheApp->MacGetCurrentEvent();
|
NSEvent* theEvent = (NSEvent*)wxTheApp->MacGetCurrentEvent();
|
||||||
wxASSERT_MSG(theEvent, "DoDragDrop must be called in response to a mouse down or drag event.");
|
wxASSERT_MSG(theEvent, "DoDragDrop must be called in response to a mouse down or drag event.");
|
||||||
|
|
||||||
|
NSPoint down = [theEvent locationInWindow];
|
||||||
|
NSPoint p = [view convertPoint:down toView:nil];
|
||||||
|
|
||||||
gCurrentSource = this;
|
gCurrentSource = this;
|
||||||
NSImage* image = [[NSImage alloc] initWithSize: NSMakeSize(16,16)];
|
|
||||||
|
// add a dummy square as dragged image for the moment,
|
||||||
|
// TODO: proper drag image for data
|
||||||
|
NSSize sz = NSMakeSize(16,16);
|
||||||
|
NSRect fillRect = NSMakeRect(0, 0, 16, 16);
|
||||||
|
NSImage* image = [[NSImage alloc] initWithSize: sz];
|
||||||
|
|
||||||
|
[image lockFocus];
|
||||||
|
|
||||||
|
[[[NSColor whiteColor] colorWithAlphaComponent:0.8] set];
|
||||||
|
NSRectFill(fillRect);
|
||||||
|
[[NSColor blackColor] set];
|
||||||
|
NSFrameRectWithWidthUsingOperation(fillRect,1.0f,NSCompositeDestinationOver);
|
||||||
|
|
||||||
|
[image unlockFocus];
|
||||||
|
|
||||||
|
|
||||||
DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
|
DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
|
||||||
[delegate setImplementation: this];
|
[delegate setImplementation: this];
|
||||||
[view dragImage:image at:NSMakePoint(0.0, 16.0) 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];
|
||||||
|
|
||||||
wxEventLoopBase * const loop = wxEventLoop::GetActive();
|
wxEventLoopBase * const loop = wxEventLoop::GetActive();
|
||||||
|
@@ -118,10 +118,16 @@ bool wxGUIEventLoop::Dispatch()
|
|||||||
inMode:NSDefaultRunLoopMode
|
inMode:NSDefaultRunLoopMode
|
||||||
dequeue: YES])
|
dequeue: YES])
|
||||||
{
|
{
|
||||||
|
WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
|
||||||
|
WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
|
||||||
|
|
||||||
if (wxTheApp)
|
if (wxTheApp)
|
||||||
wxTheApp->MacSetCurrentEvent(event, NULL);
|
wxTheApp->MacSetCurrentEvent(event, NULL);
|
||||||
m_sleepTime = 0.0;
|
m_sleepTime = 0.0;
|
||||||
[NSApp sendEvent: event];
|
[NSApp sendEvent: event];
|
||||||
|
|
||||||
|
if (wxTheApp)
|
||||||
|
wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -134,7 +134,18 @@ bool shouldHandleSelector(SEL selector)
|
|||||||
- (void)sendEvent:(NSEvent *) event
|
- (void)sendEvent:(NSEvent *) event
|
||||||
{
|
{
|
||||||
if ( ![self WX_filterSendEvent: event] )
|
if ( ![self WX_filterSendEvent: event] )
|
||||||
|
{
|
||||||
|
WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
|
||||||
|
WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
|
||||||
|
|
||||||
|
if (wxTheApp)
|
||||||
|
wxTheApp->MacSetCurrentEvent(event, NULL);
|
||||||
|
|
||||||
[super sendEvent: event];
|
[super sendEvent: event];
|
||||||
|
|
||||||
|
if (wxTheApp)
|
||||||
|
wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default implementation always moves the window back onto the screen,
|
// The default implementation always moves the window back onto the screen,
|
||||||
|
Reference in New Issue
Block a user