From 7b8cdb6b38c8d54fe1bb6837bc65575461b3dbfe Mon Sep 17 00:00:00 2001 From: jerry Date: Thu, 17 Apr 2014 17:25:41 +0000 Subject: [PATCH] used really drag file extension --- src/lib/platform/OSXDragSimulator.h | 2 +- src/lib/platform/OSXDragSimulator.m | 9 +++++++-- src/lib/platform/OSXDragView.h | 2 ++ src/lib/platform/OSXDragView.m | 10 +++++++++- src/lib/platform/OSXScreen.cpp | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/lib/platform/OSXDragSimulator.h b/src/lib/platform/OSXDragSimulator.h index 571f7e5e..f40763c3 100644 --- a/src/lib/platform/OSXDragSimulator.h +++ b/src/lib/platform/OSXDragSimulator.h @@ -26,7 +26,7 @@ extern "C" { #endif void runCocoaApp(); void stopCocoaLoop(); -void fakeDragging(const char* str, int length, int cursorX, int cursorY); +void fakeDragging(const char* str, int cursorX, int cursorY); CFStringRef getCocoaDropTarget(); #if defined(__cplusplus) diff --git a/src/lib/platform/OSXDragSimulator.m b/src/lib/platform/OSXDragSimulator.m index 0164b7f8..6e905f93 100644 --- a/src/lib/platform/OSXDragSimulator.m +++ b/src/lib/platform/OSXDragSimulator.m @@ -24,6 +24,7 @@ NSWindow* g_dragWindow = NULL; COSXDragView* g_dragView = NULL; +NSString* g_ext = NULL; void runCocoaApp() @@ -61,8 +62,10 @@ stopCocoaLoop() } void -fakeDragging(const char* str, int length, int cursorX, int cursorY) +fakeDragging(const char* str, int cursorX, int cursorY) { + g_ext = [NSString stringWithUTF8String:str]; + dispatch_async(dispatch_get_main_queue(), ^{ NSRect screen = [[NSScreen mainScreen] frame]; NSLog ( @"screen size: witdh = %f height = %f", screen.size.width, screen.size.height); @@ -80,7 +83,9 @@ fakeDragging(const char* str, int length, int cursorX, int cursorY) [g_dragWindow setFrame:rect display:NO]; [g_dragWindow makeKeyAndOrderFront:nil]; - + + [g_dragView setFileExt:g_ext]; + CGEventRef down = CGEventCreateMouseEvent(CGEventSourceCreate(kCGEventSourceStateHIDSystemState), kCGEventLeftMouseDown, CGPointMake(cursorX, cursorY), kCGMouseButtonLeft); CGEventPost(kCGHIDEventTap, down); }); diff --git a/src/lib/platform/OSXDragView.h b/src/lib/platform/OSXDragView.h index 41cf2744..00d63e88 100644 --- a/src/lib/platform/OSXDragView.h +++ b/src/lib/platform/OSXDragView.h @@ -22,10 +22,12 @@ @interface COSXDragView : NSView { NSMutableString* m_dropTarget; + NSString* m_dragFileExt; } - (CFStringRef)getDropTarget; - (void)clearDropTarget; +- (void)setFileExt:(NSString*) ext; @end diff --git a/src/lib/platform/OSXDragView.m b/src/lib/platform/OSXDragView.m index 2b03df1a..e85c43b5 100644 --- a/src/lib/platform/OSXDragView.m +++ b/src/lib/platform/OSXDragView.m @@ -30,6 +30,7 @@ initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; m_dropTarget = [[NSMutableString alloc] initWithCapacity:0]; + m_dragFileExt = [[NSMutableString alloc] initWithCapacity:0]; return self; } @@ -57,7 +58,7 @@ mouseDown:(NSEvent *)theEvent dragPosition.y -= 16; imageLocation.origin = dragPosition; imageLocation.size = NSMakeSize(32,32); - [self dragPromisedFilesOfTypes:[NSArray arrayWithObject:@"zip"] + [self dragPromisedFilesOfTypes:[NSArray arrayWithObject:m_dragFileExt] fromRect:imageLocation source:self slideBack:NO @@ -94,6 +95,13 @@ clearDropTarget [m_dropTarget setString:@""]; } +- (void) +setFileExt:(NSString*) ext +{ + m_dragFileExt = [NSString stringWithString:ext]; + NSLog(@"drag file ext: %@", m_dragFileExt); +} + - (NSWindow *) draggingDestinationWindow { diff --git a/src/lib/platform/OSXScreen.cpp b/src/lib/platform/OSXScreen.cpp index e5f10bf4..0f19bf28 100644 --- a/src/lib/platform/OSXScreen.cpp +++ b/src/lib/platform/OSXScreen.cpp @@ -2080,7 +2080,7 @@ COSXScreen::fakeDraggingFiles(CString str) m_fakeDraggingStarted = true; #if defined(MAC_OS_X_VERSION_10_7) // TODO: use real file extension - fakeDragging("txt", 3, m_xCursor, m_yCursor); + fakeDragging(str.c_str(), m_xCursor, m_yCursor); #else LOG((CLOG_WARN "drag drop not supported")); #endif