-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathsqUnixDragDrop.c
135 lines (118 loc) · 4.47 KB
/
sqUnixDragDrop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* sqUnixDragDrop.c -- support for drag and drop, for those UIs that have it
*
* Author: Ian Piumarta <[email protected]>
*
* Copyright (C) 1996-2004 by Ian Piumarta and other authors/contributors
* listed elsewhere in this file.
* All rights reserved.
*
* This file is part of Unix Squeak.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/* Why on earth does this plugin exist at all? Brain death strikes
* again. And why are half the functions never called from the VM?
* Could it be that they are only there for certain ports (we'll
* mention no names) in which the core support needs to grub around in
* this plugin via ioLoadFunctionFromModule (and, putting disbelief
* aside for a moment, maybe even VICE-VERSA)? It seems to me that
* truth is very definitely not beauty today. Sigh...
*/
#include "sq.h"
#include "sqAssert.h"
#include "sqVirtualMachine.h"
#include "FilePlugin.h"
#include "DropPlugin.h"
extern struct VirtualMachine *interpreterProxy;
extern int uxDropFileCount;
extern char **uxDropFileNames;
extern void dndReceived(char *fileName);
#if defined(SQUEAK_INTERNAL_PLUGIN)
extern SQFile * fileValueOf(sqInt objectPointer);
extern usqIntptr_t fileRecordSize(void);
#else
/* Return a pointer to the first byte of of the SQFile data structure file
record within anSQFileRecord, which is expected to be a ByteArray of size
self>>fileRecordSize.
*/
/* OSProcessPlugin>>#fileValueOf: */
static SQFile *
fileValueOf(sqInt anSQFileRecord)
{
return interpreterProxy->arrayValueOf(anSQFileRecord);
}
/* Return the size of a Smalltalk file record in bytes. */
/* FilePlugin>>#fileRecordSize */
static usqIntptr_t
fileRecordSize(void)
{
return sizeof(SQFile);
}
#endif /* defined(SQUEAK_INTERNAL_PLUGIN) */
sqInt dropInit(void) { return 1; }
sqInt dropShutdown(void) { return 1; }
/* We now set USE_FILE_URIs to 1 in platforms/unix//vm-display-X11/sqUnixXdnd.c
* hence dropRequestFileName skips the URI prefix and dropRequestURI includes it
*/
char *
dropRequestFileName(sqInt dropIndex) // in st coordinates
{
char *fileURIPrefix = "file:///";
int prefixLength = 0;
char *dropFileName;
if (dropIndex <= 0 || dropIndex > uxDropFileCount)
return 0;
assert(uxDropFileNames);
dndReceived(uxDropFileNames[dropIndex - 1]);
// The three valid schemes are
// file://host/path (prefix length 7)
// file:///path (prefix length 8)
// file:/path (prefix length 6)
// see https://en.wikipedia.org/wiki/File_URI_scheme
// Compute the length of the prefix...
if (!(dropFileName = uxDropFileNames[dropIndex - 1]))
return 0;
while (*fileURIPrefix && *fileURIPrefix++ == *dropFileName++)
++prefixLength;
// file:///path & file:/path => /path; anything else answered verbatim
return prefixLength == 8 || prefixLength == 6
? uxDropFileNames[dropIndex - 1] + prefixLength - 1
: uxDropFileNames[dropIndex - 1];
}
char *
dropRequestURI(sqInt dropIndex) // in st coordinates
{
if (dropIndex <= 0 || dropIndex > uxDropFileCount)
return 0;
assert(uxDropFileNames);
dndReceived(uxDropFileNames[dropIndex - 1]);
return uxDropFileNames[dropIndex - 1];
}
sqInt
dropRequestFileHandle(sqInt dropIndex)
{
char *path= dropRequestFileName(dropIndex);
if (path) {
// you cannot be serious?
sqInt handle = instantiateClassindexableSize(classByteArray(), fileRecordSize());
sqFileOpen(fileValueOf(handle), path, strlen(path), 0);
return handle;
}
return interpreterProxy->nilObject();
}