used really drag file extension
This commit is contained in:
parent
de65f71312
commit
7b8cdb6b38
|
@ -26,7 +26,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
void runCocoaApp();
|
void runCocoaApp();
|
||||||
void stopCocoaLoop();
|
void stopCocoaLoop();
|
||||||
void fakeDragging(const char* str, int length, int cursorX, int cursorY);
|
void fakeDragging(const char* str, int cursorX, int cursorY);
|
||||||
CFStringRef getCocoaDropTarget();
|
CFStringRef getCocoaDropTarget();
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
NSWindow* g_dragWindow = NULL;
|
NSWindow* g_dragWindow = NULL;
|
||||||
COSXDragView* g_dragView = NULL;
|
COSXDragView* g_dragView = NULL;
|
||||||
|
NSString* g_ext = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
runCocoaApp()
|
runCocoaApp()
|
||||||
|
@ -61,8 +62,10 @@ stopCocoaLoop()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSRect screen = [[NSScreen mainScreen] frame];
|
NSRect screen = [[NSScreen mainScreen] frame];
|
||||||
NSLog ( @"screen size: witdh = %f height = %f", screen.size.width, screen.size.height);
|
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 setFrame:rect display:NO];
|
||||||
|
|
||||||
[g_dragWindow makeKeyAndOrderFront:nil];
|
[g_dragWindow makeKeyAndOrderFront:nil];
|
||||||
|
|
||||||
|
[g_dragView setFileExt:g_ext];
|
||||||
|
|
||||||
CGEventRef down = CGEventCreateMouseEvent(CGEventSourceCreate(kCGEventSourceStateHIDSystemState), kCGEventLeftMouseDown, CGPointMake(cursorX, cursorY), kCGMouseButtonLeft);
|
CGEventRef down = CGEventCreateMouseEvent(CGEventSourceCreate(kCGEventSourceStateHIDSystemState), kCGEventLeftMouseDown, CGPointMake(cursorX, cursorY), kCGMouseButtonLeft);
|
||||||
CGEventPost(kCGHIDEventTap, down);
|
CGEventPost(kCGHIDEventTap, down);
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,10 +22,12 @@
|
||||||
@interface COSXDragView : NSView<NSDraggingSource,NSDraggingInfo>
|
@interface COSXDragView : NSView<NSDraggingSource,NSDraggingInfo>
|
||||||
{
|
{
|
||||||
NSMutableString* m_dropTarget;
|
NSMutableString* m_dropTarget;
|
||||||
|
NSString* m_dragFileExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CFStringRef)getDropTarget;
|
- (CFStringRef)getDropTarget;
|
||||||
- (void)clearDropTarget;
|
- (void)clearDropTarget;
|
||||||
|
- (void)setFileExt:(NSString*) ext;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ initWithFrame:(NSRect)frame
|
||||||
{
|
{
|
||||||
self = [super initWithFrame:frame];
|
self = [super initWithFrame:frame];
|
||||||
m_dropTarget = [[NSMutableString alloc] initWithCapacity:0];
|
m_dropTarget = [[NSMutableString alloc] initWithCapacity:0];
|
||||||
|
m_dragFileExt = [[NSMutableString alloc] initWithCapacity:0];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ mouseDown:(NSEvent *)theEvent
|
||||||
dragPosition.y -= 16;
|
dragPosition.y -= 16;
|
||||||
imageLocation.origin = dragPosition;
|
imageLocation.origin = dragPosition;
|
||||||
imageLocation.size = NSMakeSize(32,32);
|
imageLocation.size = NSMakeSize(32,32);
|
||||||
[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:@"zip"]
|
[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:m_dragFileExt]
|
||||||
fromRect:imageLocation
|
fromRect:imageLocation
|
||||||
source:self
|
source:self
|
||||||
slideBack:NO
|
slideBack:NO
|
||||||
|
@ -94,6 +95,13 @@ clearDropTarget
|
||||||
[m_dropTarget setString:@""];
|
[m_dropTarget setString:@""];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)
|
||||||
|
setFileExt:(NSString*) ext
|
||||||
|
{
|
||||||
|
m_dragFileExt = [NSString stringWithString:ext];
|
||||||
|
NSLog(@"drag file ext: %@", m_dragFileExt);
|
||||||
|
}
|
||||||
|
|
||||||
- (NSWindow *)
|
- (NSWindow *)
|
||||||
draggingDestinationWindow
|
draggingDestinationWindow
|
||||||
{
|
{
|
||||||
|
|
|
@ -2080,7 +2080,7 @@ COSXScreen::fakeDraggingFiles(CString str)
|
||||||
m_fakeDraggingStarted = true;
|
m_fakeDraggingStarted = true;
|
||||||
#if defined(MAC_OS_X_VERSION_10_7)
|
#if defined(MAC_OS_X_VERSION_10_7)
|
||||||
// TODO: use real file extension
|
// TODO: use real file extension
|
||||||
fakeDragging("txt", 3, m_xCursor, m_yCursor);
|
fakeDragging(str.c_str(), m_xCursor, m_yCursor);
|
||||||
#else
|
#else
|
||||||
LOG((CLOG_WARN "drag drop not supported"));
|
LOG((CLOG_WARN "drag drop not supported"));
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue