Skip to content

Commit

Permalink
Merge pull request #546 from ronsaldo/feature-osx-drop-uri-plumbing
Browse files Browse the repository at this point in the history
Plumb OS X custom url scheme events into drop events
  • Loading branch information
eliotmiranda committed Jan 15, 2021
2 parents d8b9a1a + 1fcc861 commit 35ae52c
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 39 deletions.
1 change: 1 addition & 0 deletions platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.h
Expand Up @@ -53,5 +53,6 @@
- (int) mapMouseAndModifierStateToSqueakBits: (NSEvent *) event;
- (int) translateCocoaModifiersToSqueakModifiers: (NSUInteger) modifiers;
- (void) recordDragEvent: (int) dragType numberOfFiles: (int) numFiles where: (NSPoint) local_point windowIndex: (sqInt) windowIndex view:(NSView *)aView;
- (void) recordURLEvent: (int) dragType numberOfFiles: (int) numFiles;
- (void) recordWindowEvent: (int) type window: (NSWindow *) window;
@end
17 changes: 17 additions & 0 deletions platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m
Expand Up @@ -561,6 +561,23 @@ - (void) recordDragEvent:(int)dragType numberOfFiles:(int)numFiles where:(NSPoin
interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
}

- (void) recordURLEvent:(int)dragType numberOfFiles:(int)numFiles
{
sqDragDropFilesEvent evt;

evt.type= EventTypeDragDropFiles;
evt.timeStamp= ioMSecs();
evt.dragType= dragType;
evt.x = 0;
evt.y = 0;
evt.modifiers= 0;
evt.numFiles= numFiles;
evt.windowIndex = 0;
[self pushEventToQueue: (sqInputEvent *) &evt];

interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
}

- (void) recordWindowEvent: (int) windowEventType window: (NSWindow *) window {
sqWindowEvent evt;

Expand Down
37 changes: 26 additions & 11 deletions platforms/iOS/vm/OSX/sqSqueakOSXCGView.m
Expand Up @@ -86,6 +86,11 @@ - (void)initialize {
dragItems = NULL;
clippyIsEmpty = YES;
colorspace = CGColorSpaceCreateDeviceRGB();

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void) initializeVariables {
Expand Down Expand Up @@ -566,23 +571,25 @@ - (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>
return results;
}


- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>)info {
- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedURIs: (id<NSDraggingInfo>)info {
NSPasteboard *pboard= [info draggingPasteboard];
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];
if ([[pboard types] containsObject: NSFilenamesPboardType]) {
NSArray *files= [pboard propertyListForType: NSFilenamesPboardType];
NSString *fileName;
for (fileName in files) {
if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: fileName] == NO)
[results addObject: fileName];
{
[results addObject: [NSURL fileURLWithPath: fileName]];
}
}
}

return results;
}

- (NSUInteger) countNumberOfNoneSqueakImageFilesInDraggedFiles: (id<NSDraggingInfo>)info {
NSArray *files = [self filterOutSqueakImageFilesFromDraggedFiles: info];
NSArray *files = [self filterOutSqueakImageFilesFromDraggedURIs: info];
return [files count];
}

Expand Down Expand Up @@ -616,7 +623,7 @@ - (void) draggingExited: (id<NSDraggingInfo>)info

- (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
if (self.dragCount) {
self.dragItems = [self filterOutSqueakImageFilesFromDraggedFiles: info];
self.dragItems = [self filterOutSqueakImageFilesFromDraggedURIs: info];
[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordDragEvent: SQDragDrop numberOfFiles: self.dragCount where: [info draggingLocation] windowIndex: self.windowLogic.windowIndex view: self];
}

Expand All @@ -642,13 +649,21 @@ - (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
return YES;
}

- (NSString*) dragFileNameStringAtIndex: (sqInt) index {
if (!self.dragItems)
return NULL;
if (index < 1 || index > [self.dragItems count])
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL *url = [NSURL URLWithString: urlString];
dragItems = [NSMutableArray arrayWithCapacity: 1];
[dragItems addObject: url];

[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: 1];
}

- (NSURL*) dragURIAtIndex: (sqInt) index {
if (!self.dragItems || index < 1 || index > [self.dragItems count])
return NULL;
NSString *filePath = [self.dragItems objectAtIndex: (NSUInteger) index - 1];
return filePath;

return (self.dragItems)[(NSUInteger) index - 1];
}


Expand Down
17 changes: 13 additions & 4 deletions platforms/iOS/vm/OSX/sqSqueakOSXDropAPI.m
Expand Up @@ -51,13 +51,22 @@ sqInt dropShutdown(void) {
};

char *dropRequestFileName(sqInt dropIndex) {
/* return file name or NULL if error */
NSView <sqSqueakOSXView> *view = [((sqSqueakOSXScreenAndWindow*)((__bridge NSWindow *)windowHandleFromIndex(1)).delegate) getMainViewOnWindow];
NSString *fileNameString = [view dragFileNameStringAtIndex: dropIndex];
return (char *) [fileNameString UTF8String];
NSURL *dragURIAtIndex = [view dragURIAtIndex: dropIndex];
if(!dragURIAtIndex || !dragURIAtIndex.fileURL)
return NULL;

return (char *) [dragURIAtIndex.path UTF8String];
}

char *dropRequestURI(sqInt dropIndex) { return NULL; }
char *dropRequestURI(sqInt dropIndex) {
NSView <sqSqueakOSXView> *view = [((sqSqueakOSXScreenAndWindow*)((__bridge NSWindow *)windowHandleFromIndex(1)).delegate) getMainViewOnWindow];
NSURL *dragURIAtIndex = [view dragURIAtIndex: dropIndex];
if(!dragURIAtIndex)
return NULL;

return (char *) [dragURIAtIndex.absoluteString UTF8String];
}

/* note: dropRequestFileHandle needs to bypass plugin security checks when implemented */
sqInt dropRequestFileHandle(sqInt dropIndex) {
Expand Down
34 changes: 25 additions & 9 deletions platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m
Expand Up @@ -169,6 +169,11 @@ - (void)initialize {
colorspace = CGColorSpaceCreateDeviceRGB();
[self initializeSqueakColorMap];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(didEnterFullScreen:) name:@"NSWindowDidEnterFullScreenNotification" object:nil];

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void) didEnterFullScreen: (NSNotification*) aNotification {
Expand Down Expand Up @@ -781,23 +786,25 @@ - (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>
return results;
}


- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>)info {
- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedURIs: (id<NSDraggingInfo>)info {
NSPasteboard *pboard= [info draggingPasteboard];
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];
if ([[pboard types] containsObject: NSFilenamesPboardType]) {
NSArray *files= [pboard propertyListForType: NSFilenamesPboardType];
NSString *fileName;
for (fileName in files) {
if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: fileName] == NO)
[results addObject: fileName];
{
[results addObject: [NSURL fileURLWithPath: fileName]];
}
}
}

return results;
}

- (NSUInteger) countNumberOfNoneSqueakImageFilesInDraggedFiles: (id<NSDraggingInfo>)info {
NSArray *files = [self filterOutSqueakImageFilesFromDraggedFiles: info];
NSArray *files = [self filterOutSqueakImageFilesFromDraggedURIs: info];
return [files count];
}

Expand Down Expand Up @@ -836,7 +843,7 @@ - (void) draggingExited: (id<NSDraggingInfo>)info
- (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
// NSLog(@"performDragOperation %@",info);
if (self.dragCount) {
self.dragItems = [self filterOutSqueakImageFilesFromDraggedFiles: info];
self.dragItems = [self filterOutSqueakImageFilesFromDraggedURIs: info];
[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordDragEvent: SQDragDrop numberOfFiles: self.dragCount where: [info draggingLocation] windowIndex: self.windowLogic.windowIndex view: self];
}

Expand All @@ -860,14 +867,23 @@ - (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
return YES;
}

- (NSString*) dragFileNameStringAtIndex: (sqInt) index {
if (!self.dragItems
|| index < 1 || index > [self.dragItems count])
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL *url = [NSURL URLWithString: urlString];
dragItems = [NSMutableArray arrayWithCapacity: 1];
[dragItems addObject: url];

[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: 1];
}

- (NSURL*) dragURIAtIndex: (sqInt) index {
if (!self.dragItems || index < 1 || index > [self.dragItems count])
return NULL;

return (self.dragItems)[(NSUInteger) index - 1];
}


- (BOOL)ignoreModifierKeysWhileDragging {
return YES;
}
Expand Down
36 changes: 25 additions & 11 deletions platforms/iOS/vm/OSX/sqSqueakOSXOpenGLView.m
Expand Up @@ -204,6 +204,10 @@ - (void)initialize {
[self initializeSqueakColorMap];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(didEnterFullScreen:) name:@"NSWindowDidEnterFullScreenNotification" object:nil];

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void) didEnterFullScreen: (NSNotification*) aNotification {
Expand Down Expand Up @@ -999,23 +1003,25 @@ - (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>
return results;
}


- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>)info {
- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedURIs: (id<NSDraggingInfo>)info {
NSPasteboard *pboard= [info draggingPasteboard];
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];
if ([[pboard types] containsObject: NSFilenamesPboardType]) {
NSArray *files= [pboard propertyListForType: NSFilenamesPboardType];
NSString *fileName;
for (fileName in files) {
if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: fileName] == NO)
[results addObject: fileName];
{
[results addObject: [NSURL fileURLWithPath: fileName]];
}
}
}

return results;
}

- (NSUInteger) countNumberOfNoneSqueakImageFilesInDraggedFiles: (id<NSDraggingInfo>)info {
NSArray *files = [self filterOutSqueakImageFilesFromDraggedFiles: info];
NSArray *files = [self filterOutSqueakImageFilesFromDraggedURIs: info];
return [files count];
}

Expand Down Expand Up @@ -1054,7 +1060,7 @@ - (void) draggingExited: (id<NSDraggingInfo>)info
- (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
// NSLog(@"performDragOperation %@",info);
if (self.dragCount) {
self.dragItems = [self filterOutSqueakImageFilesFromDraggedFiles: info];
self.dragItems = [self filterOutSqueakImageFilesFromDraggedURIs: info];
[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordDragEvent: SQDragDrop numberOfFiles: self.dragCount where: [info draggingLocation] windowIndex: self.windowLogic.windowIndex view: self];
}

Expand All @@ -1080,13 +1086,21 @@ - (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
return YES;
}

- (NSString*) dragFileNameStringAtIndex: (sqInt) index {
if (!self.dragItems)
return NULL;
if (index < 1 || index > [self.dragItems count])
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL *url = [NSURL URLWithString: urlString];
dragItems = [NSMutableArray arrayWithCapacity: 1];
[dragItems addObject: url];

[(sqSqueakOSXApplication *) gDelegateApp.squeakApplication recordURLEvent: SQDragDrop numberOfFiles: 1];
}

- (NSURL*) dragURIAtIndex: (sqInt) index {
if (!self.dragItems || index < 1 || index > [self.dragItems count])
return NULL;
NSString *filePath = (self.dragItems)[(NSUInteger) index - 1];
return filePath;

return (self.dragItems)[(NSUInteger) index - 1];
}


Expand Down
7 changes: 3 additions & 4 deletions platforms/iOS/vm/OSX/sqSqueakOSXView.h
Expand Up @@ -53,12 +53,11 @@
- (void) ioSetFullScreen: (sqInt) fullScreen;

- (NSUInteger) countNumberOfNoneSqueakImageFilesInDraggedFiles: (id<NSDraggingInfo>)info;
- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>)info;
- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedURIs: (id<NSDraggingInfo>)info;
- (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>)info;
- (NSString*) dragFileNameStringAtIndex:(sqInt) index;

- (NSURL*) dragURIAtIndex:(sqInt) index;
- (void) drawThelayers;
- (void) preDrawThelayers;
- (void) drawImageUsingClip: (CGRect) clip;

@end
@end

0 comments on commit 35ae52c

Please sign in to comment.