Skip to content

Commit facfd90

Browse files
committed
CogVM source as per
VMMaker.oscog-eem.2923 DropPlugin: Add primitiveDropRequestURI to support launch apple events as drop events on MacOS. Nuke the unused setFileAccessCallback:. Delete unused functions from DropPlugin.h and implementors. Currently the only full implememntation (unu=tested) is on X11/Unix. The Mac implementation is skeletal; it should be filled in real soon now.
1 parent f4f8403 commit facfd90

File tree

7 files changed

+178
-131
lines changed

7 files changed

+178
-131
lines changed

platforms/Cross/plugins/DropPlugin/DropPlugin.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
sqInt dropInit(void);
55
sqInt dropShutdown(void);
66

7-
char* dropRequestFileName(sqInt dropIndex); /* return name of file or NULL if error */
7+
char *dropRequestFileName(sqInt dropIndex); /* return name of file or NULL if error */
8+
char *dropRequestURI(sqInt dropIndex); /* return uri (if supported) or NULL if error */
89
/* note: dropRequestFileHandle needs to bypass plugin security checks when implemented */
910
sqInt dropRequestFileHandle(sqInt dropIndex); /* return READ-ONLY file handle OOP or nilObject if error */
10-
sqInt sqSecFileAccessCallback(void *);
11-
void sqSetNumberOfDropFiles(sqInt numberOfFiles);
12-
void sqSetFileInformation(sqInt dropIndex, void *dropFile);
13-
void sqDragTriggerData(char *aByteArray, sqInt dataLength, char *aFormat, sqInt formatLength);

platforms/iOS/vm/OSX/sqSqueakOSXDropAPI.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ sqInt dropShutdown(void) {
5050
return 1;
5151
};
5252

53-
char* dropRequestFileName(sqInt dropIndex) {
54-
/* return name of file or NULL if error */
53+
char *dropRequestFileName(sqInt dropIndex) {
54+
/* return file name or NULL if error */
5555
NSView <sqSqueakOSXView> *view = [((sqSqueakOSXScreenAndWindow*)((__bridge NSWindow *)windowHandleFromIndex(1)).delegate) getMainViewOnWindow];
5656
NSString *fileNameString = [view dragFileNameStringAtIndex: dropIndex];
5757
return (char *) [fileNameString UTF8String];
5858
}
5959

60+
char *dropRequestURI(sqInt dropIndex) { return NULL; }
61+
6062
/* note: dropRequestFileHandle needs to bypass plugin security checks when implemented */
6163
sqInt dropRequestFileHandle(sqInt dropIndex) {
6264

@@ -75,7 +77,3 @@ sqInt dropRequestFileHandle(sqInt dropIndex) {
7577
sqInt result = ((sqInt (*) (char * nameIndex, sqInt nameSize, sqInt writeFlag, sqInt secureFlag)) fn)(fileName,(sqInt) strlen(fileName), 0,0);
7678
return result;
7779
}
78-
79-
sqInt sqSecFileAccessCallback(void *ptr) {
80-
return 0;
81-
}

platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,12 +861,10 @@ - (BOOL) performDragOperation: (id<NSDraggingInfo>)info {
861861
}
862862

863863
- (NSString*) dragFileNameStringAtIndex: (sqInt) index {
864-
if (!self.dragItems)
864+
if (!self.dragItems
865+
|| index < 1 || index > [self.dragItems count])
865866
return NULL;
866-
if (index < 1 || index > [self.dragItems count])
867-
return NULL;
868-
NSString *filePath = (self.dragItems)[(NSUInteger) index - 1];
869-
return filePath;
867+
return (self.dragItems)[(NSUInteger) index - 1];
870868
}
871869

872870

platforms/unix/plugins/DropPlugin/sqUnixDragDrop.c

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ extern char **uxDropFileNames;
5252
extern SQFile * fileValueOf(sqInt objectPointer);
5353
#else
5454
/* Return a pointer to the first byte of of the SQFile data structure file
55-
record within
56-
anSQFileRecord, which is expected to be a ByteArray of size
55+
record within anSQFileRecord, which is expected to be a ByteArray of size
5756
self>>fileRecordSize.
5857
*/
5958

@@ -68,17 +67,53 @@ fileValueOf(sqInt anSQFileRecord)
6867
sqInt dropInit(void) { return 1; }
6968
sqInt dropShutdown(void) { return 1; }
7069

71-
char *dropRequestFileName(sqInt dropIndex) // in st coordinates
70+
/* We now set USE_FILE_URIs to 1 in platforms/unix//vm-display-X11/sqUnixXdnd.c
71+
* hence dropRequestFileName skips the URI prefix and dropRequestURI includes it
72+
*/
73+
char *
74+
dropRequestFileName(sqInt dropIndex) // in st coordinates
7275
{
73-
if ((dropIndex > 0) && (dropIndex <= uxDropFileCount)) {
74-
assert(uxDropFileNames);
75-
dndReceived(uxDropFileNames[dropIndex - 1]);
76-
return uxDropFileNames[dropIndex - 1];
77-
}
78-
return 0;
76+
char *fileURIPrefix = "file:///";
77+
int prefixLength = 0;
78+
char *dropFileName;
79+
80+
if (dropIndex <= 0 || dropIndex > uxDropFileCount)
81+
return 0;
82+
83+
assert(uxDropFileNames);
84+
dndReceived(uxDropFileNames[dropIndex - 1]);
85+
86+
// The three valid schemes are
87+
// file://host/path (prefix length 7)
88+
// file:///path (prefix length 8)
89+
// file:/path (prefix length 6)
90+
// see https://en.wikipedia.org/wiki/File_URI_scheme
91+
92+
// Compute the length of the prefix...
93+
if (!(dropFileName = uxDropFileNames[dropIndex - 1]))
94+
return 0;
95+
while (*fileURIPrefix && *fileURIPrefix++ == *dropFileName++)
96+
++prefixLength;
97+
98+
// file:///path & file:/path => path; anything else answered verbatim
99+
return prefixLength == 8 || prefixLength == 6
100+
? uxDropFileNames[dropIndex - 1] + fileURILength
101+
: uxDropFileNames[dropIndex - 1];
79102
}
80103

81-
sqInt dropRequestFileHandle(sqInt dropIndex)
104+
char *
105+
dropRequestURI(sqInt dropIndex) // in st coordinates
106+
{
107+
if (dropIndex <= 0 || dropIndex > uxDropFileCount)
108+
return 0;
109+
110+
assert(uxDropFileNames);
111+
dndReceived(uxDropFileNames[dropIndex - 1]);
112+
return uxDropFileNames[dropIndex - 1];
113+
}
114+
115+
sqInt
116+
dropRequestFileHandle(sqInt dropIndex)
82117
{
83118
char *path= dropRequestFileName(dropIndex);
84119
if (path) {
@@ -89,7 +124,3 @@ sqInt dropRequestFileHandle(sqInt dropIndex)
89124
}
90125
return interpreterProxy->nilObject();
91126
}
92-
93-
sqInt sqSecFileAccessCallback(void *callback) { return 0; }
94-
void sqSetNumberOfDropFiles(sqInt numberOfFiles) { }
95-
void sqSetFileInformation(sqInt dropIndex, void *dropFile) { }

0 commit comments

Comments
 (0)