-
Notifications
You must be signed in to change notification settings - Fork 3
/
ddcreate.c
112 lines (103 loc) · 2.52 KB
/
ddcreate.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
/*
* Drag & drop sample code.
* Copyright 1992 Atari Corporation
*
* global variables used:
* gl_apid: our AES application id
*
* BUGS/CAVEATS:
* This code is not re-entrant (it uses a static
* variable for the pipe name and for saving the
* SIGPIPE signal handler).
*
* While doing the drag and drop, the SIGPIPE
* signal (write on an empty pipe) is ignored
*/
#include "dragdrop.h"
/*
* ddcreate: create a pipe for doing the drag & drop,
* and send an AES message to the receipient
* application telling it about the drag & drop
* operation.
*
* Input Parameters:
* apid: AES id of the window owner
* winid: target window (0 for background)
* msx, msy: mouse X and Y position
* (or -1, -1 if a fake drag & drop)
* kstate: shift key state at time of event
*
* Output Parameters:
* exts: A 32 byte buffer into which the
* receipient's 8 favorite
* extensions will be copied.
*
* Returns:
* A positive file descriptor (of the opened
* drag & drop pipe) on success.
* -1 if the receipient doesn't respond or
* returns DD_NAK
* -2 if appl_write fails
*/
int dd_create(int apid, int winid, int msx, int msy, int kstate, char *exts)
{
int fd, i;
_WORD msg[8];
long fdmask;
char c;
__dragdrop_pipename[17] = __dragdrop_pipename[18] = 'A';
fd = -1;
do
{
__dragdrop_pipename[18]++;
if (__dragdrop_pipename[18] > 'Z')
{
__dragdrop_pipename[17]++;
if (__dragdrop_pipename[17] > 'Z')
break;
}
/* FA_HIDDEN means "get EOF if nobody has pipe open for reading" */
fd = (int) Fcreate(__dragdrop_pipename, FA_HIDDEN);
} while (fd == EACCES || fd == EPERM);
if (fd < 0)
return fd;
/* construct and send the AES message */
msg[0] = AP_DRAGDROP;
msg[1] = gl_apid;
msg[2] = 0;
msg[3] = winid;
msg[4] = msx;
msg[5] = msy;
msg[6] = kstate;
msg[7] = (__dragdrop_pipename[17] << 8) | __dragdrop_pipename[18];
i = appl_write(apid, (int)sizeof(msg), msg);
if (i == 0)
{
Fclose(fd);
return -2;
}
/* now wait for a response */
fdmask = 1L << fd;
i = Fselect(DD_TIMEOUT, &fdmask, 0L, 0L);
if (!i || !fdmask) /* timeout happened */
{
Fclose(fd);
return -1;
}
/* read the 1 byte response */
i = (int)Fread(fd, 1L, &c);
if (i != 1 || c != DD_OK)
{
Fclose(fd);
return -1;
}
/* now read the "preferred extensions" */
i = (int)Fread(fd, DD_EXTSIZE, exts);
if (i != DD_EXTSIZE)
{
Fclose(fd);
return -1;
}
__dragdrop_oldpipesig = (__mint_sighandler_t)Psignal(SIGPIPE, SIG_IGN);
return fd;
}