213
|
1 /* The mswindows event_stream interface.
|
|
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1996 Ben Wing.
|
|
5 Copyright (C) 1997 Jonathan Harris.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* Authorship:
|
|
27
|
|
28 Ultimately based on FSF.
|
|
29 Rewritten by Ben Wing.
|
272
|
30 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
|
213
|
31 */
|
|
32
|
|
33 #include <config.h>
|
|
34 #include "lisp.h"
|
|
35
|
249
|
36 #include "console-msw.h"
|
|
37
|
|
38 #ifdef HAVE_SCROLLBARS
|
|
39 # include "scrollbar-msw.h"
|
|
40 #endif
|
|
41
|
|
42 #ifdef HAVE_MENUBARS
|
|
43 # include "menubar-msw.h"
|
|
44 #endif
|
|
45
|
213
|
46 #include "device.h"
|
282
|
47 #include "dragdrop.h"
|
213
|
48 #include "events.h"
|
|
49 #include "frame.h"
|
274
|
50 #include "lstream.h"
|
213
|
51 #include "process.h"
|
227
|
52 #include "redisplay.h"
|
213
|
53 #include "sysproc.h"
|
|
54 #include "syswait.h"
|
|
55 #include "systime.h"
|
278
|
56 #include "sysdep.h"
|
213
|
57
|
249
|
58 #include "events-mod.h"
|
278
|
59 #ifdef HAVE_MSG_SELECT
|
|
60 #include "sysfile.h"
|
|
61 #endif
|
276
|
62 #include <io.h>
|
274
|
63 #include <errno.h>
|
|
64
|
249
|
65 #ifdef HAVE_MENUBARS
|
|
66 #define ADJR_MENUFLAG TRUE
|
|
67 #else
|
|
68 #define ADJR_MENUFLAG FALSE
|
|
69 #endif
|
|
70
|
|
71 /* Fake key modifier which is attached to a quit char event.
|
|
72 Removed upon dequeueing an event */
|
|
73 #define FAKE_MOD_QUIT 0x80
|
|
74
|
|
75 /* Timer ID used for button2 emulation */
|
|
76 #define BUTTON_2_TIMER_ID 1
|
|
77
|
278
|
78 extern Lisp_Object
|
|
79 mswindows_get_toolbar_button_text (struct frame* f, int command_id);
|
|
80 extern Lisp_Object
|
|
81 mswindows_handle_toolbar_wm_command (struct frame* f, HWND ctrl, WORD id);
|
249
|
82
|
|
83 static Lisp_Object mswindows_find_frame (HWND hwnd);
|
|
84 static Lisp_Object mswindows_find_console (HWND hwnd);
|
|
85 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods);
|
|
86 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr);
|
|
87 static void mswindows_set_chord_timer (HWND hwnd);
|
|
88 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
|
|
89 static int mswindows_current_layout_has_AltGr (void);
|
|
90
|
213
|
91 static struct event_stream *mswindows_event_stream;
|
223
|
92
|
278
|
93 #ifdef HAVE_MSG_SELECT
|
|
94 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
|
|
95 extern SELECT_TYPE process_only_mask, tty_only_mask;
|
|
96 extern int signal_event_pipe_initialized;
|
|
97 int windows_fd;
|
|
98 #endif
|
|
99
|
223
|
100 /*
|
|
101 * Two separate queues, for efficiency, one (_u_) for user events, and
|
|
102 * another (_s_) for non-user ones. We always return events out of the
|
|
103 * first one until it is empty and only then proceed with the second
|
|
104 * one.
|
|
105 */
|
|
106 static Lisp_Object mswindows_u_dispatch_event_queue, mswindows_u_dispatch_event_queue_tail;
|
|
107 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
|
213
|
108
|
249
|
109 /* The number of things we can wait on */
|
|
110 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
|
|
111
|
|
112 /* List of mswindows waitable handles. */
|
274
|
113 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
|
|
114
|
|
115 /* Number of wait handles */
|
|
116 static int mswindows_waitable_count=0;
|
213
|
117
|
223
|
118 /* Count of quit chars currently in the queue */
|
249
|
119 /* Incremented in WM_[SYS]KEYDOWN handler in the mswindows_wnd_proc()
|
223
|
120 Decremented in mswindows_dequeue_dispatch_event() */
|
|
121 int mswindows_quit_chars_count = 0;
|
|
122
|
|
123 /* These are Lisp integers; see DEFVARS in this file for description. */
|
|
124 int mswindows_dynamic_frame_resize;
|
|
125 int mswindows_num_mouse_buttons;
|
272
|
126 int mswindows_mouse_button_max_skew_x;
|
|
127 int mswindows_mouse_button_max_skew_y;
|
|
128 int mswindows_mouse_button_tolerance;
|
223
|
129
|
227
|
130 /* This is the event signaled by the event pump.
|
|
131 See mswindows_pump_outstanding_events for comments */
|
231
|
132 static Lisp_Object mswindows_error_caught_in_modal_loop;
|
|
133 static int mswindows_in_modal_loop;
|
227
|
134
|
|
135 /* Count of wound timers */
|
|
136 static int mswindows_pending_timers_count;
|
274
|
137
|
|
138 /************************************************************************/
|
|
139 /* Pipe instream - reads process output */
|
|
140 /************************************************************************/
|
|
141
|
|
142 #define PIPE_READ_DELAY 20
|
|
143
|
|
144 #define HANDLE_TO_USID(h) ((USID)(h))
|
|
145
|
|
146 #define NTPIPE_SLURP_STREAM_DATA(stream) \
|
|
147 LSTREAM_TYPE_DATA (stream, ntpipe_slurp)
|
|
148
|
276
|
149 /* This structure is allocated by the main thread, and is deallocated
|
|
150 in the thread upon exit. There are situations when a thread
|
|
151 remains blocked for a long time, much longer than the lstream
|
|
152 exists. For exmaple, "start notepad" command is issued from the
|
|
153 shell, then the shell is closed by C-c C-d. Although the shell
|
|
154 process exits, its output pipe will not get closed until the
|
|
155 notepad process exits also, because it inherits the pipe form the
|
|
156 shell. In this case, we abandon the thread, and let it live until
|
|
157 all such processes exit. While struct ntpipe_slurp_stream is
|
|
158 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */
|
|
159
|
|
160 struct ntpipe_slurp_stream_shared_data
|
274
|
161 {
|
|
162 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
|
|
163 /* This is a manual-reset object. */
|
|
164 HANDLE hev_caller; /* Caller blocks on this, and we signal it */
|
|
165 /* This is a manual-reset object. */
|
|
166 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */
|
|
167 /* This is a manual-reset object. */
|
|
168 HANDLE hpipe; /* Pipe read end handle. */
|
276
|
169 LONG die_p; /* Thread must exit ASAP if non-zero */
|
274
|
170 BOOL eof_p : 1; /* Set when thread saw EOF */
|
|
171 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
|
276
|
172 BOOL inuse_p : 1; /* this structure is in use */
|
|
173 LONG lock_count; /* Client count of this struct, 0=safe to free */
|
|
174 BYTE onebyte; /* One byte buffer read by thread */
|
|
175 };
|
|
176
|
|
177 #define MAX_SLURP_STREAMS 32
|
|
178 struct ntpipe_slurp_stream_shared_data
|
278
|
179 shared_data_block[MAX_SLURP_STREAMS]={{0}};
|
276
|
180
|
|
181 struct ntpipe_slurp_stream
|
|
182 {
|
|
183 LPARAM user_data; /* Any user data stored in the stream object */
|
|
184 struct ntpipe_slurp_stream_shared_data* thread_data;
|
274
|
185 };
|
|
186
|
|
187 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-input", lstream_ntpipe_slurp,
|
|
188 sizeof (struct ntpipe_slurp_stream));
|
|
189
|
276
|
190 /* This function is thread-safe, and is called from either thread
|
|
191 context. It serializes freeing shared dtata structure */
|
|
192 static void
|
|
193 slurper_free_shared_data_maybe (struct ntpipe_slurp_stream_shared_data* s)
|
|
194 {
|
|
195 if (InterlockedDecrement (&s->lock_count) == 0)
|
|
196 {
|
|
197 /* Destroy events */
|
|
198 CloseHandle (s->hev_thread);
|
|
199 CloseHandle (s->hev_caller);
|
|
200 CloseHandle (s->hev_unsleep);
|
|
201 s->inuse_p = 0;
|
|
202 }
|
|
203 }
|
|
204
|
|
205 static struct ntpipe_slurp_stream_shared_data*
|
|
206 slurper_allocate_shared_data()
|
|
207 {
|
|
208 int i=0;
|
|
209 for (i=0; i<MAX_SLURP_STREAMS; i++)
|
|
210 {
|
|
211 if (!shared_data_block[i].inuse_p)
|
|
212 {
|
|
213 shared_data_block[i].inuse_p=1;
|
|
214 return &shared_data_block[i];
|
|
215 }
|
|
216 }
|
|
217 return (struct ntpipe_slurp_stream_shared_data*)0;
|
|
218 }
|
|
219
|
274
|
220 static DWORD WINAPI
|
|
221 slurp_thread (LPVOID vparam)
|
|
222 {
|
276
|
223 struct ntpipe_slurp_stream_shared_data *s =
|
|
224 (struct ntpipe_slurp_stream_shared_data*)vparam;
|
274
|
225
|
|
226 for (;;)
|
|
227 {
|
|
228 /* Read one byte from the pipe */
|
|
229 DWORD actually_read;
|
|
230 if (!ReadFile (s->hpipe, &s->onebyte, 1, &actually_read, NULL))
|
|
231 {
|
|
232 DWORD err = GetLastError ();
|
|
233 if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
|
|
234 s->eof_p = TRUE;
|
|
235 else
|
|
236 s->error_p = TRUE;
|
|
237 }
|
|
238 else if (actually_read == 0)
|
|
239 s->eof_p = TRUE;
|
|
240
|
|
241 /* We must terminate on an error or eof */
|
|
242 if (s->eof_p || s->error_p)
|
|
243 InterlockedIncrement (&s->die_p);
|
|
244
|
|
245 /* Before we notify caller, we unsignal our event. */
|
|
246 ResetEvent (s->hev_thread);
|
|
247
|
|
248 /* Now we got something to notify caller, either a byte or an
|
|
249 error/eof indication. Before we do, allow internal pipe
|
|
250 buffer to accumulate little bit more data.
|
|
251 Reader function pulses this event before waiting for
|
276
|
252 a character, to avoid pipe delay, and to get the byte
|
274
|
253 immediately. */
|
|
254 if (!s->die_p)
|
|
255 WaitForSingleObject (s->hev_unsleep, PIPE_READ_DELAY);
|
|
256
|
|
257 /* Either make event loop generate a process event, or
|
|
258 inblock reader */
|
|
259 SetEvent (s->hev_caller);
|
|
260
|
|
261 /* Cleanup and exit if we're shot off */
|
|
262 if (s->die_p)
|
|
263 break;
|
|
264
|
|
265 /* Block until the client finishes with retireving the rest of
|
|
266 pipe data */
|
|
267 WaitForSingleObject (s->hev_thread, INFINITE);
|
|
268 }
|
|
269
|
276
|
270 slurper_free_shared_data_maybe (s);
|
|
271
|
274
|
272 return 0;
|
|
273 }
|
|
274
|
|
275 static Lisp_Object
|
|
276 make_ntpipe_input_stream (HANDLE hpipe, LPARAM param)
|
|
277 {
|
|
278 Lisp_Object obj;
|
|
279 Lstream *lstr = Lstream_new (lstream_ntpipe_slurp, "r");
|
|
280 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA (lstr);
|
|
281 DWORD thread_id_unused;
|
276
|
282 HANDLE hthread;
|
274
|
283
|
|
284 /* We deal only with pipes, for we're using PeekNamedPipe api */
|
|
285 assert (GetFileType (hpipe) == FILE_TYPE_PIPE);
|
|
286
|
276
|
287 s->thread_data = slurper_allocate_shared_data();
|
274
|
288
|
276
|
289 /* Create reader thread. This could fail, so do not create events
|
|
290 until thread is created */
|
|
291 hthread = CreateThread (NULL, 0, slurp_thread, (LPVOID)s->thread_data,
|
|
292 CREATE_SUSPENDED, &thread_id_unused);
|
|
293 if (hthread == NULL)
|
274
|
294 {
|
|
295 Lstream_delete (lstr);
|
276
|
296 s->thread_data->inuse_p=0;
|
274
|
297 return Qnil;
|
|
298 }
|
|
299
|
276
|
300 /* Shared data are initially owned by both main and slurper
|
|
301 threads. */
|
|
302 s->thread_data->lock_count = 2;
|
|
303 s->thread_data->die_p = 0;
|
|
304 s->thread_data->eof_p = FALSE;
|
|
305 s->thread_data->error_p = FALSE;
|
|
306 s->thread_data->hpipe = hpipe;
|
|
307 s->user_data = param;
|
|
308
|
274
|
309 /* hev_thread is a manual-reset event, initially signaled */
|
276
|
310 s->thread_data->hev_thread = CreateEvent (NULL, TRUE, TRUE, NULL);
|
274
|
311 /* hev_caller is a manual-reset event, initially nonsignaled */
|
276
|
312 s->thread_data->hev_caller = CreateEvent (NULL, TRUE, FALSE, NULL);
|
274
|
313 /* hev_unsleep is a manual-reset event, initially nonsignaled */
|
276
|
314 s->thread_data->hev_unsleep = CreateEvent (NULL, TRUE, FALSE, NULL);
|
274
|
315
|
|
316 /* Now let it go */
|
276
|
317 ResumeThread (hthread);
|
|
318 CloseHandle (hthread);
|
274
|
319
|
|
320 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
|
321 XSETLSTREAM (obj, lstr);
|
|
322 return obj;
|
|
323 }
|
|
324
|
|
325 static LPARAM
|
|
326 get_ntpipe_input_stream_param (Lstream *stream)
|
|
327 {
|
|
328 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
|
|
329 return s->user_data;
|
|
330 }
|
|
331
|
|
332 static HANDLE
|
|
333 get_ntpipe_input_stream_waitable (Lstream *stream)
|
|
334 {
|
|
335 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
|
276
|
336 return s->thread_data->hev_caller;
|
274
|
337 }
|
|
338
|
|
339 static int
|
|
340 ntpipe_slurp_reader (Lstream *stream, unsigned char *data, size_t size)
|
|
341 {
|
|
342 /* This function must be called from the main thread only */
|
276
|
343 struct ntpipe_slurp_stream_shared_data* s =
|
|
344 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
|
274
|
345
|
|
346 if (!s->die_p)
|
|
347 {
|
|
348 DWORD wait_result;
|
276
|
349 /* Disallow pipe read delay for the thread: we need a character
|
|
350 ASAP */
|
274
|
351 SetEvent (s->hev_unsleep);
|
|
352
|
276
|
353 /* Check if we have a character ready. Give it a short delay,
|
|
354 for the thread to awake from pipe delay, just ion case*/
|
274
|
355 wait_result = WaitForSingleObject (s->hev_caller, 2);
|
|
356
|
|
357 /* Revert to the normal sleep behavior. */
|
|
358 ResetEvent (s->hev_unsleep);
|
|
359
|
|
360 /* If there's no byte buffered yet, give up */
|
|
361 if (wait_result == WAIT_TIMEOUT)
|
|
362 {
|
|
363 errno = EAGAIN;
|
|
364 return -1;
|
|
365 }
|
|
366 }
|
|
367
|
|
368 /* Reset caller unlock event now, as we've handled the pending
|
|
369 process output event */
|
|
370 ResetEvent (s->hev_caller);
|
|
371
|
|
372 /* It is now safe to do anything with contents of S, except for
|
|
373 changing s->die_p, which still should be interlocked */
|
|
374
|
|
375 if (s->eof_p)
|
|
376 return 0;
|
|
377 if (s->error_p || s->die_p)
|
|
378 return -1;
|
|
379
|
276
|
380 /* Ok, there were no error neither eof - we've got a byte from the
|
|
381 pipe */
|
274
|
382 *(data++) = s->onebyte;
|
|
383 --size;
|
|
384
|
276
|
385 {
|
|
386 DWORD bytes_read = 0;
|
|
387 if (size > 0)
|
|
388 {
|
|
389 DWORD bytes_available;
|
274
|
390
|
276
|
391 /* If the api call fails, return at least one byte already
|
|
392 read. ReadFile in thread will return error */
|
|
393 if (PeekNamedPipe (s->hpipe, NULL, 0, NULL, &bytes_available, NULL))
|
|
394 {
|
274
|
395
|
276
|
396 /* Fetch available bytes. The same consideration applies,
|
|
397 so do not check for errors. ReadFile in the thread will
|
|
398 fail if the next call fails. */
|
|
399 if (bytes_available)
|
|
400 ReadFile (s->hpipe, data, min (bytes_available, size),
|
|
401 &bytes_read, NULL);
|
|
402 }
|
|
403
|
|
404 /* Now we can unblock thread, so it attempts to read more */
|
|
405 SetEvent (s->hev_thread);
|
|
406 return bytes_read + 1;
|
|
407 }
|
|
408 }
|
278
|
409 return 0;
|
274
|
410 }
|
|
411
|
|
412 static int
|
|
413 ntpipe_slurp_closer (Lstream *stream)
|
|
414 {
|
|
415 /* This function must be called from the main thread only */
|
276
|
416 struct ntpipe_slurp_stream_shared_data* s =
|
|
417 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
|
274
|
418
|
|
419 /* Force thread to stop */
|
|
420 InterlockedIncrement (&s->die_p);
|
|
421
|
276
|
422 /* Set events which could possibly block slurper. Let it finish soon
|
|
423 or later. */
|
274
|
424 SetEvent (s->hev_unsleep);
|
|
425 SetEvent (s->hev_thread);
|
|
426
|
276
|
427 /* Unlock and maybe free shared data */
|
|
428 slurper_free_shared_data_maybe (s);
|
274
|
429
|
|
430 return 0;
|
|
431 }
|
|
432
|
|
433 static void
|
|
434 init_slurp_stream (void)
|
|
435 {
|
|
436 LSTREAM_HAS_METHOD (ntpipe_slurp, reader);
|
|
437 LSTREAM_HAS_METHOD (ntpipe_slurp, closer);
|
|
438 }
|
|
439
|
|
440 /************************************************************************/
|
|
441 /* Pipe outstream - writes process input */
|
|
442 /************************************************************************/
|
|
443
|
|
444 #define NTPIPE_SHOVE_STREAM_DATA(stream) \
|
|
445 LSTREAM_TYPE_DATA (stream, ntpipe_shove)
|
|
446
|
276
|
447 #define MAX_SHOVE_BUFFER_SIZE 128
|
|
448
|
274
|
449 struct ntpipe_shove_stream
|
|
450 {
|
|
451 LPARAM user_data; /* Any user data stored in the stream object */
|
|
452 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
|
|
453 /* This is an auto-reset object. */
|
|
454 HANDLE hpipe; /* Pipe write end handle. */
|
|
455 HANDLE hthread; /* Reader thread handle. */
|
276
|
456 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */
|
274
|
457 DWORD size; /* Number of bytes to write */
|
276
|
458 LONG die_p; /* Thread must exit ASAP if non-zero */
|
|
459 LONG idle_p; /* Non-zero if thread is waiting for job */
|
274
|
460 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
|
|
461 BOOL blocking_p : 1;/* Last write attempt would cause blocking */
|
|
462 };
|
|
463
|
|
464 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", lstream_ntpipe_shove,
|
|
465 sizeof (struct ntpipe_shove_stream));
|
|
466
|
|
467 static DWORD WINAPI
|
|
468 shove_thread (LPVOID vparam)
|
|
469 {
|
|
470 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream*) vparam;
|
|
471
|
|
472 for (;;)
|
|
473 {
|
|
474 DWORD bytes_written;
|
|
475
|
|
476 /* Block on event and wait for a job */
|
|
477 InterlockedIncrement (&s->idle_p);
|
|
478 WaitForSingleObject (s->hev_thread, INFINITE);
|
|
479
|
|
480 if (s->die_p)
|
|
481 break;
|
|
482
|
|
483 /* Write passed buffer */
|
|
484 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL)
|
|
485 || bytes_written != s->size)
|
|
486 {
|
|
487 s->error_p = TRUE;
|
|
488 InterlockedIncrement (&s->die_p);
|
|
489 }
|
|
490
|
|
491 if (s->die_p)
|
|
492 break;
|
|
493 }
|
|
494
|
|
495 return 0;
|
|
496 }
|
|
497
|
|
498 static Lisp_Object
|
|
499 make_ntpipe_output_stream (HANDLE hpipe, LPARAM param)
|
|
500 {
|
|
501 Lisp_Object obj;
|
|
502 Lstream *lstr = Lstream_new (lstream_ntpipe_shove, "w");
|
|
503 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA (lstr);
|
|
504 DWORD thread_id_unused;
|
|
505
|
|
506 s->die_p = 0;
|
|
507 s->error_p = FALSE;
|
|
508 s->hpipe = hpipe;
|
|
509 s->user_data = param;
|
|
510
|
|
511 /* Create reader thread. This could fail, so do not
|
|
512 create the event until thread is created */
|
|
513 s->hthread = CreateThread (NULL, 0, shove_thread, (LPVOID)s,
|
|
514 CREATE_SUSPENDED, &thread_id_unused);
|
|
515 if (s->hthread == NULL)
|
|
516 {
|
|
517 Lstream_delete (lstr);
|
|
518 return Qnil;
|
|
519 }
|
|
520
|
|
521 /* hev_thread is an auto-reset event, initially nonsignaled */
|
|
522 s->hev_thread = CreateEvent (NULL, FALSE, FALSE, NULL);
|
|
523
|
|
524 /* Now let it go */
|
|
525 ResumeThread (s->hthread);
|
|
526
|
|
527 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
|
528 XSETLSTREAM (obj, lstr);
|
|
529 return obj;
|
|
530 }
|
|
531
|
|
532 static LPARAM
|
|
533 get_ntpipe_output_stream_param (Lstream *stream)
|
|
534 {
|
|
535 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
536 return s->user_data;
|
|
537 }
|
|
538
|
|
539 static int
|
|
540 ntpipe_shove_writer (Lstream *stream, const unsigned char *data, size_t size)
|
|
541 {
|
|
542 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
543
|
|
544 if (s->error_p)
|
|
545 return -1;
|
|
546
|
|
547 s->blocking_p = !s->idle_p;
|
|
548 if (s->blocking_p)
|
|
549 return 0;
|
|
550
|
276
|
551 if (size>MAX_SHOVE_BUFFER_SIZE)
|
|
552 return 0;
|
|
553
|
274
|
554 memcpy (s->buffer, data, size);
|
|
555 s->size = size;
|
|
556
|
|
557 /* Start output */
|
|
558 InterlockedDecrement (&s->idle_p);
|
|
559 SetEvent (s->hev_thread);
|
|
560 return size;
|
|
561 }
|
|
562
|
|
563 static int
|
|
564 ntpipe_shove_was_blocked_p (Lstream *stream)
|
|
565 {
|
|
566 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
567 return s->blocking_p;
|
|
568 }
|
|
569
|
|
570 static int
|
|
571 ntpipe_shove_closer (Lstream *stream)
|
|
572 {
|
|
573 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
574
|
|
575 /* Force thread stop */
|
|
576 InterlockedIncrement (&s->die_p);
|
|
577
|
|
578 /* Close pipe handle, possibly breaking it */
|
|
579 CloseHandle (s->hpipe);
|
|
580
|
|
581 /* Thread will end upon unblocking */
|
|
582 SetEvent (s->hev_thread);
|
|
583
|
|
584 /* Wait while thread terminates */
|
|
585 WaitForSingleObject (s->hthread, INFINITE);
|
|
586 CloseHandle (s->hthread);
|
|
587
|
|
588 /* Destroy the event */
|
|
589 CloseHandle (s->hev_thread);
|
|
590
|
|
591 return 0;
|
|
592 }
|
|
593
|
|
594 static void
|
|
595 init_shove_stream (void)
|
|
596 {
|
|
597 LSTREAM_HAS_METHOD (ntpipe_shove, writer);
|
|
598 LSTREAM_HAS_METHOD (ntpipe_shove, was_blocked_p);
|
|
599 LSTREAM_HAS_METHOD (ntpipe_shove, closer);
|
|
600 }
|
|
601
|
|
602 /************************************************************************/
|
282
|
603 /* Winsock I/O stream */
|
|
604 /************************************************************************/
|
|
605 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
606
|
|
607 #define WINSOCK_READ_BUFFER_SIZE 1024
|
|
608
|
|
609 struct winsock_stream
|
|
610 {
|
|
611 LPARAM user_data; /* Any user data stored in the stream object */
|
|
612 SOCKET s; /* Socket handle (which is a Win32 handle) */
|
|
613 OVERLAPPED ov; /* Overlapped I/O structure */
|
|
614 void* buffer; /* Buffer. Allocated for input stream only */
|
|
615 unsigned int bufsize; /* Number of bytes last read */
|
|
616 unsigned int bufpos; /* Psition in buffer for next fetch */
|
|
617 unsigned int error_p :1; /* I/O Error seen */
|
|
618 unsigned int eof_p :1; /* EOF Error seen */
|
|
619 unsigned int pending_p :1; /* There is a pending I/O operation */
|
|
620 unsigned int blocking_p :1; /* Last write attempt would block */
|
|
621 };
|
|
622
|
|
623 #define WINSOCK_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, winsock)
|
|
624
|
|
625 DEFINE_LSTREAM_IMPLEMENTATION ("winsock", lstream_winsock,
|
|
626 sizeof (struct winsock_stream));
|
|
627
|
|
628 static void
|
|
629 winsock_initiate_read (struct winsock_stream *str)
|
|
630 {
|
|
631 ResetEvent (str->ov.hEvent);
|
|
632 str->bufpos = 0;
|
|
633
|
|
634 if (!ReadFile ((HANDLE)str->s, str->buffer, WINSOCK_READ_BUFFER_SIZE,
|
|
635 &str->bufsize, &str->ov))
|
|
636 {
|
|
637 if (GetLastError () == ERROR_IO_PENDING)
|
|
638 str->pending_p = 1;
|
|
639 else if (GetLastError () == ERROR_HANDLE_EOF)
|
|
640 str->eof_p = 1;
|
|
641 else
|
|
642 str->error_p = 1;
|
|
643 }
|
|
644 else if (str->bufsize == 0)
|
|
645 str->eof_p = 1;
|
|
646 }
|
|
647
|
|
648 static int
|
|
649 winsock_reader (Lstream *stream, unsigned char *data, size_t size)
|
|
650 {
|
|
651 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
652
|
|
653 /* If the current operation is not yet complete, there's nothing to
|
|
654 give back */
|
|
655 if (str->pending_p)
|
|
656 {
|
|
657 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
|
|
658 {
|
|
659 errno = EAGAIN;
|
|
660 return -1;
|
|
661 }
|
|
662 else
|
|
663 {
|
|
664 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize, TRUE))
|
|
665 {
|
|
666 if (GetLastError() == ERROR_HANDLE_EOF)
|
|
667 str->bufsize = 0;
|
|
668 else
|
|
669 str->error_p = 1;
|
|
670 }
|
|
671 if (str->bufsize == 0)
|
|
672 str->eof_p = 1;
|
|
673 str->pending_p = 0;
|
|
674 }
|
|
675 }
|
|
676
|
|
677 if (str->eof_p)
|
|
678 return 0;
|
|
679 if (str->error_p)
|
|
680 return -1;
|
|
681
|
|
682 /* Return as much of buffer as we have */
|
|
683 size = min (size, (size_t) (str->bufsize - str->bufpos));
|
|
684 memcpy (data, (void*)((BYTE*)str->buffer + str->bufpos), size);
|
|
685 str->bufpos += size;
|
|
686
|
|
687 /* Read more if buffer is exhausted */
|
|
688 if (str->bufsize == str->bufpos)
|
|
689 winsock_initiate_read (str);
|
|
690
|
|
691 return size;
|
|
692 }
|
|
693
|
|
694 static int
|
|
695 winsock_writer (Lstream *stream, CONST unsigned char *data, size_t size)
|
|
696 {
|
|
697 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
698
|
|
699 if (str->pending_p)
|
|
700 {
|
|
701 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
|
|
702 {
|
|
703 str->blocking_p = 1;
|
|
704 return -1;
|
|
705 }
|
|
706 else
|
|
707 {
|
|
708 DWORD dw_unused;
|
|
709 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused, TRUE))
|
|
710 str->error_p = 1;
|
|
711 str->pending_p = 0;
|
|
712 }
|
|
713 }
|
|
714
|
|
715 str->blocking_p = 0;
|
|
716
|
|
717 if (str->error_p)
|
|
718 return -1;
|
|
719
|
|
720 if (size == 0)
|
|
721 return 0;
|
|
722
|
|
723 {
|
|
724 ResetEvent (str->ov.hEvent);
|
|
725
|
|
726 if (WriteFile ((HANDLE)str->s, data, size, NULL, &str->ov)
|
|
727 || GetLastError() == ERROR_IO_PENDING)
|
|
728 str->pending_p = 1;
|
|
729 else
|
|
730 str->error_p = 1;
|
|
731 }
|
|
732
|
|
733 return str->error_p ? -1 : size;
|
|
734 }
|
|
735
|
|
736 static int
|
|
737 winsock_closer (Lstream *lstr)
|
|
738 {
|
|
739 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
740
|
|
741 if (lstr->flags & LSTREAM_FL_READ)
|
|
742 shutdown (str->s, 0);
|
|
743 else
|
|
744 shutdown (str->s, 1);
|
|
745
|
|
746 CloseHandle ((HANDLE)str->s);
|
|
747 if (str->pending_p)
|
|
748 WaitForSingleObject (str->ov.hEvent, INFINITE);
|
|
749
|
|
750 if (lstr->flags & LSTREAM_FL_READ)
|
|
751 xfree (str->buffer);
|
|
752
|
|
753 CloseHandle (str->ov.hEvent);
|
|
754 return 0;
|
|
755 }
|
|
756
|
|
757 static int
|
|
758 winsock_was_blocked_p (Lstream *stream)
|
|
759 {
|
|
760 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
761 return str->blocking_p;
|
|
762 }
|
|
763
|
|
764 static Lisp_Object
|
|
765 make_winsock_stream_1 (SOCKET s, LPARAM param, CONST char *mode)
|
|
766 {
|
|
767 Lisp_Object obj;
|
|
768 Lstream *lstr = Lstream_new (lstream_winsock, mode);
|
|
769 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
770
|
|
771 str->s = s;
|
|
772 str->blocking_p = 0;
|
|
773 str->error_p = 0;
|
|
774 str->eof_p = 0;
|
|
775 str->pending_p = 0;
|
|
776 str->user_data = param;
|
|
777
|
|
778 xzero (str->ov);
|
|
779 str->ov.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
|
|
780
|
|
781 if (lstr->flags & LSTREAM_FL_READ)
|
|
782 {
|
|
783 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE);
|
|
784 winsock_initiate_read (str);
|
|
785 }
|
|
786
|
|
787 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
|
788 XSETLSTREAM (obj, lstr);
|
|
789 return obj;
|
|
790 }
|
|
791
|
|
792 static Lisp_Object
|
|
793 make_winsock_input_stream (SOCKET s, LPARAM param)
|
|
794 {
|
|
795 return make_winsock_stream_1 (s, param, "r");
|
|
796 }
|
|
797
|
|
798 static Lisp_Object
|
|
799 make_winsock_output_stream (SOCKET s, LPARAM param)
|
|
800 {
|
|
801 return make_winsock_stream_1 (s, param, "w");
|
|
802 }
|
|
803
|
|
804 static HANDLE
|
|
805 get_winsock_stream_waitable (Lstream *lstr)
|
|
806 {
|
|
807 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
808 return str->ov.hEvent;
|
|
809 }
|
|
810
|
|
811 static LPARAM
|
|
812 get_winsock_stream_param (Lstream *lstr)
|
|
813 {
|
|
814 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
815 return str->user_data;
|
|
816 }
|
|
817
|
|
818 static void
|
|
819 init_winsock_stream (void)
|
|
820 {
|
|
821 LSTREAM_HAS_METHOD (winsock, reader);
|
|
822 LSTREAM_HAS_METHOD (winsock, writer);
|
|
823 LSTREAM_HAS_METHOD (winsock, closer);
|
|
824 LSTREAM_HAS_METHOD (winsock, was_blocked_p);
|
|
825 }
|
|
826 #endif /* defined (HAVE_SOCKETS) */
|
|
827
|
|
828 /************************************************************************/
|
274
|
829 /* Dispatch queue management */
|
|
830 /************************************************************************/
|
227
|
831
|
223
|
832 static int
|
|
833 mswindows_user_event_p (struct Lisp_Event* sevt)
|
|
834 {
|
|
835 return (sevt->event_type == key_press_event
|
|
836 || sevt->event_type == button_press_event
|
282
|
837 || sevt->event_type == button_release_event);
|
223
|
838 }
|
|
839
|
249
|
840 /*
|
223
|
841 * Add an emacs event to the proper dispatch queue
|
219
|
842 */
|
276
|
843 static void
|
213
|
844 mswindows_enqueue_dispatch_event (Lisp_Object event)
|
|
845 {
|
223
|
846 int user_p = mswindows_user_event_p (XEVENT(event));
|
|
847 enqueue_event (event,
|
|
848 user_p ? &mswindows_u_dispatch_event_queue :
|
|
849 &mswindows_s_dispatch_event_queue,
|
|
850 user_p ? &mswindows_u_dispatch_event_queue_tail :
|
|
851 &mswindows_s_dispatch_event_queue_tail);
|
|
852
|
276
|
853 /* Avoid blocking on WaitMessage */
|
223
|
854 PostMessage (NULL, XM_BUMPQUEUE, 0, 0);
|
213
|
855 }
|
|
856
|
249
|
857 void
|
276
|
858 mswindows_bump_queue (void)
|
|
859 {
|
|
860 /* Bump queue, by putting in an empty event */
|
|
861 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
862 struct Lisp_Event* event = XEVENT (emacs_event);
|
|
863
|
|
864 event->event_type = empty_event;
|
|
865
|
|
866 mswindows_enqueue_dispatch_event (emacs_event);
|
|
867 }
|
|
868
|
|
869 static void
|
249
|
870 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
|
|
871 {
|
|
872 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
873 struct Lisp_Event* event = XEVENT (emacs_event);
|
|
874
|
|
875 event->channel = mswindows_find_frame (hwnd);
|
|
876 event->timestamp = GetMessageTime();
|
|
877 event->event_type = magic_event;
|
|
878 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
|
|
879
|
|
880 mswindows_enqueue_dispatch_event (emacs_event);
|
|
881 }
|
|
882
|
|
883 static void
|
274
|
884 mswindows_enqueue_process_event (struct Lisp_Process* p)
|
|
885 {
|
|
886 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
887 struct Lisp_Event* event = XEVENT (emacs_event);
|
|
888 Lisp_Object process;
|
|
889 XSETPROCESS (process, p);
|
|
890
|
|
891 event->event_type = process_event;
|
|
892 event->timestamp = GetTickCount ();
|
|
893 event->event.process.process = process;
|
|
894
|
|
895 mswindows_enqueue_dispatch_event (emacs_event);
|
|
896 }
|
|
897
|
|
898 static void
|
249
|
899 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT message, POINTS where, DWORD when)
|
|
900 {
|
|
901
|
|
902 /* We always use last message time, because mouse button
|
|
903 events may get delayed, and XEmacs double click
|
|
904 recognition will fail */
|
|
905
|
|
906 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
907 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
908
|
|
909 event->channel = mswindows_find_frame(hwnd);
|
|
910 event->timestamp = when;
|
|
911 event->event.button.button =
|
|
912 (message==WM_LBUTTONDOWN || message==WM_LBUTTONUP) ? 1 :
|
|
913 ((message==WM_RBUTTONDOWN || message==WM_RBUTTONUP) ? 3 : 2);
|
|
914 event->event.button.x = where.x;
|
|
915 event->event.button.y = where.y;
|
|
916 event->event.button.modifiers = mswindows_modifier_state (NULL, 0);
|
|
917
|
|
918 if (message==WM_LBUTTONDOWN || message==WM_MBUTTONDOWN ||
|
|
919 message==WM_RBUTTONDOWN)
|
|
920 {
|
|
921 event->event_type = button_press_event;
|
|
922 SetCapture (hwnd);
|
|
923 }
|
|
924 else
|
|
925 {
|
|
926 event->event_type = button_release_event;
|
|
927 ReleaseCapture ();
|
|
928 }
|
|
929
|
|
930 mswindows_enqueue_dispatch_event (emacs_event);
|
|
931 }
|
|
932
|
|
933 static void
|
|
934 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
|
|
935 {
|
|
936 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
937 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
938
|
|
939 event->channel = mswindows_find_console(hwnd);
|
|
940 event->timestamp = GetMessageTime();
|
|
941 event->event_type = key_press_event;
|
|
942 event->event.key.keysym = keysym;
|
|
943 event->event.key.modifiers = mods;
|
|
944 mswindows_enqueue_dispatch_event (emacs_event);
|
|
945 }
|
|
946
|
219
|
947 /*
|
223
|
948 * Remove and return the first emacs event on the dispatch queue.
|
|
949 * Give a preference to user events over non-user ones.
|
219
|
950 */
|
213
|
951 static Lisp_Object
|
223
|
952 mswindows_dequeue_dispatch_event ()
|
213
|
953 {
|
|
954 Lisp_Object event;
|
223
|
955 struct Lisp_Event* sevt;
|
|
956
|
|
957 assert (!NILP(mswindows_u_dispatch_event_queue) ||
|
|
958 !NILP(mswindows_s_dispatch_event_queue));
|
|
959
|
|
960 event = dequeue_event (
|
|
961 NILP(mswindows_u_dispatch_event_queue) ?
|
|
962 &mswindows_s_dispatch_event_queue :
|
|
963 &mswindows_u_dispatch_event_queue,
|
|
964 NILP(mswindows_u_dispatch_event_queue) ?
|
|
965 &mswindows_s_dispatch_event_queue_tail :
|
|
966 &mswindows_u_dispatch_event_queue_tail);
|
|
967
|
|
968 sevt = XEVENT(event);
|
|
969 if (sevt->event_type == key_press_event
|
|
970 && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
|
|
971 {
|
|
972 sevt->event.key.modifiers &= ~FAKE_MOD_QUIT;
|
|
973 --mswindows_quit_chars_count;
|
|
974 }
|
|
975
|
213
|
976 return event;
|
|
977 }
|
|
978
|
|
979 /*
|
219
|
980 * Remove and return the first emacs event on the dispatch queue that matches
|
223
|
981 * the supplied event
|
|
982 * Timeout event matches if interval_id equals to that of the given event.
|
|
983 * Keypress event matches if logical AND between modifiers bitmask of the
|
|
984 * event in the queue and that of the given event is non-zero
|
|
985 * For all other event types, this function asserts.
|
219
|
986 */
|
223
|
987
|
219
|
988 Lisp_Object
|
223
|
989 mswindows_cancel_dispatch_event (struct Lisp_Event* match)
|
219
|
990 {
|
|
991 Lisp_Object event;
|
|
992 Lisp_Object previous_event=Qnil;
|
223
|
993 int user_p = mswindows_user_event_p (match);
|
|
994 Lisp_Object* head = user_p ? &mswindows_u_dispatch_event_queue :
|
|
995 &mswindows_s_dispatch_event_queue;
|
|
996 Lisp_Object* tail = user_p ? &mswindows_u_dispatch_event_queue_tail :
|
|
997 &mswindows_s_dispatch_event_queue_tail;
|
219
|
998
|
223
|
999 assert (match->event_type == timeout_event
|
|
1000 || match->event_type == key_press_event);
|
219
|
1001
|
223
|
1002 EVENT_CHAIN_LOOP (event, *head)
|
|
1003 {
|
|
1004 int found = 1;
|
|
1005 if (XEVENT_TYPE (event) != match->event_type)
|
|
1006 found = 0;
|
|
1007 if (found && match->event_type == timeout_event
|
|
1008 && (XEVENT(event)->event.timeout.interval_id !=
|
|
1009 match->event.timeout.interval_id))
|
|
1010 found = 0;
|
|
1011 if (found && match->event_type == key_press_event
|
|
1012 && ((XEVENT(event)->event.key.modifiers &
|
|
1013 match->event.key.modifiers) == 0))
|
|
1014 found = 0;
|
|
1015
|
|
1016 if (found)
|
|
1017 {
|
|
1018 if (NILP (previous_event))
|
|
1019 dequeue_event (head, tail);
|
|
1020 else
|
|
1021 {
|
|
1022 XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event));
|
|
1023 if (EQ (*tail, event))
|
|
1024 *tail = previous_event;
|
|
1025 }
|
|
1026
|
|
1027 return event;
|
|
1028 }
|
219
|
1029 previous_event = event;
|
223
|
1030 }
|
239
|
1031 return Qnil;
|
219
|
1032 }
|
274
|
1033
|
|
1034 /************************************************************************/
|
|
1035 /* Waitable handles manipulation */
|
|
1036 /************************************************************************/
|
|
1037 static int
|
|
1038 find_waitable_handle (HANDLE h)
|
|
1039 {
|
|
1040 int i;
|
|
1041 for (i = 0; i < mswindows_waitable_count; ++i)
|
|
1042 if (mswindows_waitable_handles[i] == h)
|
|
1043 return i;
|
219
|
1044
|
274
|
1045 return -1;
|
|
1046 }
|
249
|
1047
|
274
|
1048 static BOOL
|
|
1049 add_waitable_handle (HANDLE h)
|
|
1050 {
|
|
1051 assert (find_waitable_handle (h) < 0);
|
|
1052 if (mswindows_waitable_count == MAX_WAITABLE)
|
|
1053 return FALSE;
|
|
1054
|
|
1055 mswindows_waitable_handles [mswindows_waitable_count++] = h;
|
|
1056 return TRUE;
|
|
1057 }
|
|
1058
|
|
1059 static void
|
|
1060 remove_waitable_handle (HANDLE h)
|
|
1061 {
|
|
1062 int ix = find_waitable_handle (h);
|
|
1063 if (ix < 0)
|
|
1064 return;
|
|
1065
|
|
1066 mswindows_waitable_handles [ix] =
|
|
1067 mswindows_waitable_handles [--mswindows_waitable_count];
|
|
1068 }
|
|
1069
|
|
1070
|
249
|
1071 /************************************************************************/
|
|
1072 /* Event pump */
|
|
1073 /************************************************************************/
|
|
1074
|
231
|
1075 static Lisp_Object
|
|
1076 mswindows_modal_loop_error_handler (Lisp_Object cons_sig_data,
|
|
1077 Lisp_Object u_n_u_s_e_d)
|
|
1078 {
|
|
1079 mswindows_error_caught_in_modal_loop = cons_sig_data;
|
|
1080 return Qunbound;
|
|
1081 }
|
|
1082
|
|
1083 Lisp_Object
|
|
1084 mswindows_protect_modal_loop (Lisp_Object (*bfun) (Lisp_Object barg),
|
|
1085 Lisp_Object barg)
|
|
1086 {
|
|
1087 Lisp_Object tmp;
|
|
1088
|
|
1089 ++mswindows_in_modal_loop;
|
|
1090 tmp = condition_case_1 (Qt,
|
|
1091 bfun, barg,
|
|
1092 mswindows_modal_loop_error_handler, Qnil);
|
|
1093 --mswindows_in_modal_loop;
|
|
1094
|
|
1095 return tmp;
|
|
1096 }
|
|
1097
|
|
1098 void
|
|
1099 mswindows_unmodalize_signal_maybe (void)
|
|
1100 {
|
|
1101 if (!NILP (mswindows_error_caught_in_modal_loop))
|
|
1102 {
|
|
1103 /* Got an error while messages were pumped while
|
|
1104 in window procedure - have to resignal */
|
|
1105 Lisp_Object sym = XCAR (mswindows_error_caught_in_modal_loop);
|
|
1106 Lisp_Object data = XCDR (mswindows_error_caught_in_modal_loop);
|
|
1107 mswindows_error_caught_in_modal_loop = Qnil;
|
|
1108 Fsignal (sym, data);
|
|
1109 }
|
|
1110 }
|
|
1111
|
219
|
1112 /*
|
227
|
1113 * This is an unsafe part of event pump, guarded by
|
|
1114 * condition_case. See mswindows_pump_outstanding_events
|
|
1115 */
|
|
1116 static Lisp_Object
|
|
1117 mswindows_unsafe_pump_events (Lisp_Object u_n_u_s_e_d)
|
|
1118 {
|
|
1119 /* This function can call lisp */
|
|
1120 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
1121 struct gcpro gcpro1;
|
|
1122 int do_redisplay = 0;
|
|
1123 GCPRO1 (event);
|
|
1124
|
|
1125 while (detect_input_pending ())
|
|
1126 {
|
|
1127 Fnext_event (event, Qnil);
|
|
1128 Fdispatch_event (event);
|
|
1129 do_redisplay = 1;
|
|
1130 }
|
|
1131
|
|
1132 if (do_redisplay)
|
|
1133 redisplay ();
|
|
1134
|
|
1135 Fdeallocate_event (event);
|
|
1136 UNGCPRO;
|
|
1137
|
|
1138 /* Qt becomes return value of mswindows_pump_outstanding_events
|
|
1139 once we get here */
|
|
1140 return Qt;
|
|
1141 }
|
|
1142
|
|
1143 /*
|
|
1144 * This function pumps emacs events, while available, by using
|
|
1145 * next_message/dispatch_message loop. Errors are trapped around
|
|
1146 * the loop so the function always returns.
|
|
1147 *
|
|
1148 * Windows message queue is not looked into during the call,
|
|
1149 * neither are waitable handles checked. The function pumps
|
|
1150 * thus only dispatch events already queued, as well as those
|
|
1151 * resulted in dispatching thereof. This is done by setting
|
231
|
1152 * module local variable mswidows_in_modal_loop to nonzero.
|
227
|
1153 *
|
231
|
1154 * Return value is Qt if no errors was trapped, or Qunbound if
|
227
|
1155 * there was an error.
|
|
1156 *
|
|
1157 * In case of error, a cons representing the error, in the
|
|
1158 * form (SIGNAL . DATA), is stored in the module local variable
|
231
|
1159 * mswindows_error_caught_in_modal_loop. This error is signaled
|
227
|
1160 * again when DispatchMessage returns. Thus, Windows internal
|
|
1161 * modal loops are protected against throws, which are proven
|
|
1162 * to corrupt internal Windows structures.
|
|
1163 *
|
231
|
1164 * In case of success, mswindows_error_caught_in_modal_loop is
|
227
|
1165 * assigned Qnil.
|
|
1166 *
|
231
|
1167 * If the value of mswindows_error_caught_in_modal_loop is not
|
227
|
1168 * nil already upon entry, the function just returns non-nil.
|
|
1169 * This situation means that a new event has been queued while
|
|
1170 * cancleng mode. The event will be dequeued on the next regular
|
|
1171 * call of next-event; the pump is off since error is caught.
|
|
1172 * The caller must *unconditionally* cancel modal loop if the
|
|
1173 * value returned by this function is nil. Otherwise, everything
|
|
1174 * will become frozen until the modal loop exits under normal
|
|
1175 * condition (scrollbar drag is released, menu closed etc.)
|
|
1176 */
|
|
1177 Lisp_Object
|
|
1178 mswindows_pump_outstanding_events (void)
|
|
1179 {
|
|
1180 /* This function can call lisp */
|
|
1181
|
|
1182 Lisp_Object result = Qt;
|
249
|
1183 struct gcpro gcpro1;
|
|
1184 GCPRO1 (result);
|
|
1185
|
231
|
1186 if (NILP(mswindows_error_caught_in_modal_loop))
|
|
1187 result = mswindows_protect_modal_loop (mswindows_unsafe_pump_events, Qnil);
|
249
|
1188 UNGCPRO;
|
227
|
1189 return result;
|
|
1190 }
|
|
1191
|
223
|
1192 static void
|
|
1193 mswindows_drain_windows_queue ()
|
|
1194 {
|
|
1195 MSG msg;
|
|
1196 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
|
227
|
1197 {
|
|
1198 DispatchMessage (&msg);
|
231
|
1199 mswindows_unmodalize_signal_maybe ();
|
227
|
1200 }
|
|
1201 }
|
|
1202
|
|
1203 /*
|
|
1204 * This is a special flavour of the mswindows_need_event function,
|
|
1205 * used while in event pump. Actually, there is only kind of events
|
|
1206 * allowed while in event pump: a timer. An attempt to fetch any
|
|
1207 * other event leads to a dealock, as there's no source of user input
|
|
1208 * ('cause event pump mirrors windows modal loop, which is a sole
|
|
1209 * owner of thread message queue).
|
|
1210 *
|
|
1211 * To detect this, we use a counter of active timers, and allow
|
|
1212 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
|
|
1213 * which will never come when there are no pending timers, which leads
|
|
1214 * to deadlock, we simply signal an error.
|
|
1215 */
|
|
1216 static void
|
274
|
1217 mswindows_need_event_in_modal_loop (int badly_p)
|
227
|
1218 {
|
|
1219 MSG msg;
|
|
1220
|
|
1221 /* Check if already have one */
|
|
1222 if (!NILP (mswindows_u_dispatch_event_queue)
|
|
1223 || !NILP (mswindows_s_dispatch_event_queue))
|
|
1224 return;
|
|
1225
|
|
1226 /* No event is ok */
|
|
1227 if (!badly_p)
|
|
1228 return;
|
|
1229
|
|
1230 /* We do not check the _u_ queue, because timers go to _s_ */
|
|
1231 while (NILP (mswindows_s_dispatch_event_queue))
|
|
1232 {
|
|
1233 /* We'll deadlock if go waiting */
|
|
1234 if (mswindows_pending_timers_count == 0)
|
|
1235 error ("Deadlock due to an attempt to call next-event in a wrong context");
|
|
1236
|
|
1237 /* Fetch and dispatch any pending timers */
|
|
1238 GetMessage (&msg, NULL, WM_TIMER, WM_TIMER);
|
|
1239 DispatchMessage (&msg);
|
|
1240 }
|
223
|
1241 }
|
|
1242
|
|
1243 /*
|
|
1244 * This drains the event queue and fills up two internal queues until
|
|
1245 * an event of a type specified by USER_P is retrieved.
|
|
1246 *
|
|
1247 *
|
|
1248 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
|
|
1249 */
|
|
1250 static void
|
274
|
1251 mswindows_need_event (int badly_p)
|
223
|
1252 {
|
|
1253 int active;
|
|
1254
|
231
|
1255 if (mswindows_in_modal_loop)
|
227
|
1256 {
|
274
|
1257 mswindows_need_event_in_modal_loop (badly_p);
|
227
|
1258 return;
|
|
1259 }
|
|
1260
|
223
|
1261 /* Have to drain Windows message queue first, otherwise, we may miss
|
|
1262 quit char when called from quit_p */
|
|
1263 mswindows_drain_windows_queue ();
|
|
1264
|
274
|
1265 while (NILP (mswindows_u_dispatch_event_queue)
|
|
1266 && NILP (mswindows_s_dispatch_event_queue))
|
278
|
1267 {
|
|
1268 #ifdef HAVE_MSG_SELECT
|
|
1269 int i;
|
|
1270 SELECT_TYPE temp_mask = input_wait_mask;
|
|
1271 EMACS_TIME sometime;
|
|
1272 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
|
|
1273
|
|
1274 if (badly_p)
|
|
1275 pointer_to_this = 0;
|
|
1276 else
|
|
1277 {
|
|
1278 EMACS_SET_SECS_USECS (sometime, 0, 0);
|
|
1279 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
|
|
1280 pointer_to_this = &select_time_to_block;
|
|
1281 }
|
|
1282 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
|
|
1283
|
|
1284 if (active == 0)
|
|
1285 {
|
|
1286 return; /* timeout */
|
|
1287 }
|
|
1288 else if (active > 0)
|
|
1289 {
|
|
1290 if (FD_ISSET (windows_fd, &temp_mask))
|
|
1291 {
|
|
1292 mswindows_drain_windows_queue ();
|
|
1293 }
|
|
1294
|
|
1295 /* Look for a process event */
|
|
1296 for (i = 0; i < MAXDESC-1; i++)
|
|
1297 {
|
|
1298 if (FD_ISSET (i, &temp_mask))
|
|
1299 {
|
|
1300 if (FD_ISSET (i, &process_only_mask))
|
|
1301 {
|
|
1302 struct Lisp_Process *p =
|
|
1303 get_process_from_usid (FD_TO_USID(i));
|
|
1304
|
|
1305 mswindows_enqueue_process_event (p);
|
|
1306 }
|
|
1307 else if (FD_ISSET (i, &tty_only_mask))
|
|
1308 {
|
|
1309 /* do we care about tty events? Do we
|
|
1310 ever get tty events? */
|
|
1311 }
|
|
1312 else
|
|
1313 {
|
|
1314 /* We might get here when a fake event came
|
|
1315 through a signal. Return a dummy event, so
|
|
1316 that a cycle of the command loop will
|
|
1317 occur. */
|
|
1318 drain_signal_event_pipe ();
|
|
1319 mswindows_bump_queue();
|
|
1320 }
|
|
1321 }
|
|
1322 }
|
|
1323 }
|
|
1324 else if (active==-1)
|
|
1325 {
|
|
1326 if (errno != EINTR)
|
|
1327 {
|
|
1328 /* something bad happended */
|
|
1329 assert(0);
|
|
1330 }
|
|
1331 }
|
|
1332 else
|
|
1333 {
|
|
1334 assert(0);
|
|
1335 }
|
|
1336 #else
|
|
1337 /* Now try getting a message or process event */
|
223
|
1338 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
|
274
|
1339 mswindows_waitable_handles,
|
223
|
1340 FALSE, badly_p ? INFINITE : 0,
|
|
1341 QS_ALLINPUT);
|
|
1342
|
|
1343 /* This will assert if handle being waited for becomes abandoned.
|
|
1344 Not the case currently tho */
|
|
1345 assert ((!badly_p && active == WAIT_TIMEOUT) ||
|
|
1346 (active >= WAIT_OBJECT_0 &&
|
|
1347 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
|
|
1348
|
|
1349 if (active == WAIT_TIMEOUT)
|
|
1350 {
|
|
1351 /* No luck trying - just return what we've already got */
|
|
1352 return;
|
|
1353 }
|
|
1354 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
|
|
1355 {
|
|
1356 /* Got your message, thanks */
|
|
1357 mswindows_drain_windows_queue ();
|
|
1358 }
|
|
1359 else
|
|
1360 {
|
274
|
1361 int ix = active - WAIT_OBJECT_0;
|
|
1362 /* First, try to find which process' ouptut has signaled */
|
|
1363 struct Lisp_Process *p =
|
|
1364 get_process_from_usid (HANDLE_TO_USID (mswindows_waitable_handles[ix]));
|
|
1365 if (p != NULL)
|
|
1366 {
|
|
1367 /* Found a signaled process input handle */
|
|
1368 mswindows_enqueue_process_event (p);
|
|
1369 }
|
|
1370 else
|
|
1371 {
|
|
1372 /* None. This means that the process handle itself has signaled.
|
|
1373 Remove the handle from the wait vector, and make status_ntoify
|
|
1374 note the exited process */
|
|
1375 mswindows_waitable_handles [ix] =
|
|
1376 mswindows_waitable_handles [--mswindows_waitable_count];
|
|
1377 kick_status_notify ();
|
276
|
1378 /* Have to return something: there may be no accompanying
|
|
1379 process event */
|
|
1380 mswindows_bump_queue ();
|
274
|
1381 }
|
223
|
1382 }
|
278
|
1383 #endif
|
223
|
1384 } /* while */
|
|
1385 }
|
|
1386
|
249
|
1387 /************************************************************************/
|
|
1388 /* Event generators */
|
|
1389 /************************************************************************/
|
|
1390
|
|
1391 /*
|
|
1392 * Callback procedure for synchronous timer messages
|
|
1393 */
|
|
1394 static void CALLBACK
|
|
1395 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
|
|
1396 {
|
|
1397 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
1398 struct Lisp_Event *event = XEVENT (emacs_event);
|
|
1399
|
|
1400 if (KillTimer (NULL, id_timer))
|
|
1401 --mswindows_pending_timers_count;
|
|
1402
|
|
1403 event->channel = Qnil;
|
|
1404 event->timestamp = dwtime;
|
|
1405 event->event_type = timeout_event;
|
|
1406 event->event.timeout.interval_id = id_timer;
|
|
1407
|
|
1408 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1409 }
|
|
1410
|
|
1411 /*
|
|
1412 * Callback procedure for dde messages
|
|
1413 */
|
|
1414 HDDEDATA CALLBACK
|
|
1415 mswindows_dde_callback (UINT uType, UINT uFmt, HCONV hconv,
|
|
1416 HSZ hszTopic, HSZ hszItem, HDDEDATA hdata,
|
|
1417 DWORD dwData1, DWORD dwData2)
|
|
1418 {
|
|
1419 switch (uType)
|
|
1420 {
|
|
1421 case XTYP_CONNECT:
|
|
1422 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
|
|
1423 return (HDDEDATA)TRUE;
|
|
1424 return (HDDEDATA)FALSE;
|
|
1425
|
|
1426 case XTYP_WILDCONNECT:
|
|
1427 {
|
|
1428 /* We only support one {service,topic} pair */
|
|
1429 HSZPAIR pairs[2] = {
|
|
1430 { mswindows_dde_service, mswindows_dde_topic_system }, { 0, 0 } };
|
|
1431
|
|
1432 if (!(hszItem || DdeCmpStringHandles (hszItem, mswindows_dde_service)) &&
|
|
1433 !(hszTopic || DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)));
|
|
1434 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE)pairs,
|
|
1435 sizeof (pairs), 0L, 0, uFmt, 0));
|
|
1436 }
|
|
1437 return (HDDEDATA)NULL;
|
|
1438
|
|
1439 case XTYP_EXECUTE:
|
|
1440 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
|
|
1441 {
|
|
1442 DWORD len = DdeGetData (hdata, NULL, 0, 0);
|
|
1443 char *cmd = alloca (len+1);
|
|
1444 char *end;
|
282
|
1445 char *filename;
|
|
1446 struct gcpro gcpro1, gcpro2;
|
|
1447 Lisp_Object l_dndlist = Qnil;
|
249
|
1448 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
1449 struct Lisp_Event *event = XEVENT (emacs_event);
|
|
1450
|
|
1451 DdeGetData (hdata, cmd, len, 0);
|
|
1452 cmd[len] = '\0';
|
|
1453 DdeFreeDataHandle (hdata);
|
|
1454
|
282
|
1455 /* Check syntax & that it's an [Open("foo")] command, which we
|
|
1456 * treat like a file drop */
|
249
|
1457 /* #### Ought to be generalised and accept some other commands */
|
|
1458 if (*cmd == '[')
|
|
1459 cmd++;
|
|
1460 if (strnicmp (cmd, MSWINDOWS_DDE_ITEM_OPEN,
|
|
1461 strlen (MSWINDOWS_DDE_ITEM_OPEN)))
|
|
1462 return DDE_FNOTPROCESSED;
|
|
1463 cmd += strlen (MSWINDOWS_DDE_ITEM_OPEN);
|
|
1464 while (*cmd==' ')
|
|
1465 cmd++;
|
|
1466 if (*cmd!='(' || *(cmd+1)!='\"')
|
|
1467 return DDE_FNOTPROCESSED;
|
|
1468 end = (cmd+=2);
|
|
1469 while (*end && *end!='\"')
|
|
1470 end++;
|
|
1471 if (!*end)
|
|
1472 return DDE_FNOTPROCESSED;
|
|
1473 *end = '\0';
|
|
1474 if (*(++end)!=')')
|
|
1475 return DDE_FNOTPROCESSED;
|
|
1476 if (*(++end)==']')
|
|
1477 end++;
|
|
1478 if (*end)
|
|
1479 return DDE_FNOTPROCESSED;
|
282
|
1480
|
259
|
1481 #ifdef __CYGWIN32__
|
282
|
1482 filename = alloca (cygwin32_win32_to_posix_path_list_buf_size (cmd) + 5);
|
|
1483 strcpy (filename, "file:");
|
|
1484 cygwin32_win32_to_posix_path_list (cmd, filename+5);
|
|
1485 #else
|
|
1486 dostounix_filename (cmd);
|
|
1487 filename = alloca (strlen (cmd)+6);
|
|
1488 strcpy (filename, "file:");
|
|
1489 strcat (filename, cmd);
|
259
|
1490 #endif
|
282
|
1491 GCPRO2 (emacs_event, l_dndlist);
|
|
1492 l_dndlist = make_string (filename, strlen (filename));
|
249
|
1493
|
|
1494 event->channel = Qnil;
|
|
1495 event->timestamp = GetTickCount();
|
282
|
1496 event->event_type = misc_user_event;
|
|
1497 event->event.misc.button = 1;
|
|
1498 event->event.misc.modifiers = 0;
|
|
1499 event->event.misc.x = -1;
|
|
1500 event->event.misc.y = -1;
|
|
1501 event->event.misc.function = Qdragdrop_drop_dispatch;
|
|
1502 event->event.misc.object = Fcons (Qdragdrop_URL,
|
|
1503 Fcons (l_dndlist, Qnil));
|
249
|
1504 mswindows_enqueue_dispatch_event (emacs_event);
|
282
|
1505 UNGCPRO;
|
249
|
1506 return (HDDEDATA) DDE_FACK;
|
|
1507 }
|
|
1508 DdeFreeDataHandle (hdata);
|
|
1509 return (HDDEDATA) DDE_FNOTPROCESSED;
|
282
|
1510
|
249
|
1511 default:
|
|
1512 return (HDDEDATA) NULL;
|
|
1513 }
|
|
1514
|
|
1515 }
|
|
1516
|
|
1517 /*
|
|
1518 * The windows procedure for the window class XEMACS_CLASS
|
|
1519 */
|
|
1520 LRESULT WINAPI
|
|
1521 mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
1522 {
|
|
1523 /* Note: Remember to initialise emacs_event and event before use.
|
|
1524 This code calls code that can GC. You must GCPRO before calling such code. */
|
|
1525 Lisp_Object emacs_event = Qnil;
|
|
1526 Lisp_Object fobj = Qnil;
|
|
1527
|
|
1528 struct Lisp_Event *event;
|
|
1529 struct frame *frame;
|
|
1530 struct mswindows_frame* msframe;
|
|
1531
|
|
1532 switch (message)
|
|
1533 {
|
|
1534 case WM_ERASEBKGND:
|
|
1535 /* Erase background only during non-dynamic sizing */
|
|
1536 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1537 if (msframe->sizing && !mswindows_dynamic_frame_resize)
|
|
1538 goto defproc;
|
|
1539 return 1;
|
|
1540
|
|
1541 case WM_CLOSE:
|
|
1542 fobj = mswindows_find_frame (hwnd);
|
|
1543 enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
|
276
|
1544 mswindows_bump_queue ();
|
249
|
1545 break;
|
|
1546
|
|
1547 case WM_KEYDOWN:
|
|
1548 case WM_SYSKEYDOWN:
|
|
1549 {
|
|
1550 BYTE keymap[256];
|
|
1551 int has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
1552 int mods;
|
|
1553 Lisp_Object keysym;
|
|
1554
|
|
1555 GetKeyboardState (keymap);
|
|
1556 mods = mswindows_modifier_state (keymap, has_AltGr);
|
|
1557
|
|
1558 /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */
|
|
1559 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
|
|
1560 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
|
|
1561 else
|
|
1562 {
|
|
1563 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
|
|
1564 BYTE keymap_orig[256];
|
|
1565 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) };
|
|
1566 memcpy (keymap_orig, keymap, 256);
|
|
1567
|
|
1568 /* Clear control and alt modifiers out of the keymap */
|
|
1569 keymap [VK_RCONTROL] = 0;
|
|
1570 keymap [VK_LMENU] = 0;
|
|
1571 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80))
|
|
1572 {
|
|
1573 keymap [VK_LCONTROL] = 0;
|
|
1574 keymap [VK_CONTROL] = 0;
|
|
1575 keymap [VK_RMENU] = 0;
|
|
1576 keymap [VK_MENU] = 0;
|
|
1577 }
|
|
1578 SetKeyboardState (keymap);
|
|
1579
|
|
1580 /* Have some WM_[SYS]CHARS in the queue */
|
|
1581 TranslateMessage (&msg);
|
|
1582
|
|
1583 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
|
|
1584 ||PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE))
|
|
1585 {
|
|
1586 int ch = msg.wParam;
|
|
1587 /* CH is a character code for the key:
|
|
1588 'C' for Shift+C and Ctrl+Shift+C
|
|
1589 'c' for c and Ctrl+c */
|
|
1590
|
|
1591 /* #### If locale is not C, US or other latin-1,
|
|
1592 isalpha() maybe not what do we mean */
|
|
1593
|
|
1594 /* XEmacs doesn't seem to like Shift on non-alpha keys */
|
|
1595 if (!isalpha(ch))
|
|
1596 mods &= ~MOD_SHIFT;
|
|
1597
|
|
1598 /* Un-capitalise alpha control keys */
|
|
1599 if ((mods & MOD_CONTROL) && isalpha(ch))
|
|
1600 ch |= ('A' ^ 'a');
|
|
1601
|
|
1602 /* If a quit char with no modifiers other than control and
|
|
1603 shift, then mark it with a fake modifier, which is removed
|
|
1604 upon dequeueing the event */
|
|
1605 /* #### This might also not withstand localization, if
|
|
1606 quit character is not a latin-1 symbol */
|
|
1607 if (((quit_ch < ' ' && (mods & MOD_CONTROL) && quit_ch + 'a' - 1 == ch)
|
|
1608 || (quit_ch >= ' ' && !(mods & MOD_CONTROL) && quit_ch == ch))
|
|
1609 && ((mods & ~(MOD_CONTROL | MOD_SHIFT)) == 0))
|
|
1610 {
|
|
1611 mods |= FAKE_MOD_QUIT;
|
|
1612 ++mswindows_quit_chars_count;
|
|
1613 }
|
|
1614
|
|
1615 mswindows_enqueue_keypress_event (hwnd, make_char(ch), mods);
|
|
1616 } /* while */
|
|
1617 SetKeyboardState (keymap_orig);
|
|
1618 } /* else */
|
|
1619 }
|
|
1620 goto defproc;
|
|
1621
|
|
1622 case WM_MBUTTONDOWN:
|
|
1623 case WM_MBUTTONUP:
|
|
1624 /* Real middle mouse button has nothing to do with emulated one:
|
|
1625 if one wants to exercise fingers playing chords on the mouse,
|
|
1626 he is allowed to do that! */
|
|
1627 mswindows_enqueue_mouse_button_event (hwnd, message,
|
|
1628 MAKEPOINTS (lParam), GetMessageTime());
|
|
1629 break;
|
|
1630
|
|
1631 case WM_LBUTTONUP:
|
|
1632 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1633 msframe->last_click_time = GetMessageTime();
|
|
1634
|
|
1635 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
1636 msframe->button2_need_lbutton = 0;
|
|
1637 if (msframe->ignore_next_lbutton_up)
|
|
1638 {
|
|
1639 msframe->ignore_next_lbutton_up = 0;
|
|
1640 }
|
|
1641 else if (msframe->button2_is_down)
|
|
1642 {
|
|
1643 msframe->button2_is_down = 0;
|
|
1644 msframe->ignore_next_rbutton_up = 1;
|
|
1645 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
1646 MAKEPOINTS (lParam), GetMessageTime());
|
|
1647 }
|
|
1648 else
|
|
1649 {
|
|
1650 if (msframe->button2_need_rbutton)
|
|
1651 {
|
|
1652 msframe->button2_need_rbutton = 0;
|
|
1653 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
1654 MAKEPOINTS (lParam), GetMessageTime());
|
|
1655 }
|
|
1656 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
|
|
1657 MAKEPOINTS (lParam), GetMessageTime());
|
|
1658 }
|
|
1659 break;
|
|
1660
|
|
1661 case WM_RBUTTONUP:
|
|
1662 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1663 msframe->last_click_time = GetMessageTime();
|
|
1664
|
|
1665 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
1666 msframe->button2_need_rbutton = 0;
|
|
1667 if (msframe->ignore_next_rbutton_up)
|
|
1668 {
|
|
1669 msframe->ignore_next_rbutton_up = 0;
|
|
1670 }
|
|
1671 else if (msframe->button2_is_down)
|
|
1672 {
|
|
1673 msframe->button2_is_down = 0;
|
|
1674 msframe->ignore_next_lbutton_up = 1;
|
|
1675 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
1676 MAKEPOINTS (lParam), GetMessageTime());
|
|
1677 }
|
|
1678 else
|
|
1679 {
|
|
1680 if (msframe->button2_need_lbutton)
|
|
1681 {
|
|
1682 msframe->button2_need_lbutton = 0;
|
|
1683 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
1684 MAKEPOINTS (lParam), GetMessageTime());
|
|
1685 }
|
|
1686 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
|
|
1687 MAKEPOINTS (lParam), GetMessageTime());
|
|
1688 }
|
|
1689 break;
|
|
1690
|
|
1691 case WM_LBUTTONDOWN:
|
|
1692 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1693
|
|
1694 if (msframe->button2_need_lbutton)
|
|
1695 {
|
|
1696 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
1697 msframe->button2_need_lbutton = 0;
|
|
1698 msframe->button2_need_rbutton = 0;
|
|
1699 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
|
1700 {
|
|
1701 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
1702 MAKEPOINTS (lParam), GetMessageTime());
|
|
1703 msframe->button2_is_down = 1;
|
|
1704 }
|
|
1705 else
|
|
1706 {
|
|
1707 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
1708 msframe->last_click_point, msframe->last_click_time);
|
|
1709 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
1710 MAKEPOINTS (lParam), GetMessageTime());
|
|
1711 }
|
|
1712 }
|
|
1713 else
|
|
1714 {
|
|
1715 mswindows_set_chord_timer (hwnd);
|
|
1716 msframe->button2_need_rbutton = 1;
|
|
1717 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
1718 }
|
|
1719 msframe->last_click_time = GetMessageTime();
|
|
1720 break;
|
|
1721
|
|
1722 case WM_RBUTTONDOWN:
|
|
1723 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1724
|
|
1725 if (msframe->button2_need_rbutton)
|
|
1726 {
|
|
1727 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
1728 msframe->button2_need_lbutton = 0;
|
|
1729 msframe->button2_need_rbutton = 0;
|
|
1730 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
|
1731 {
|
|
1732 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
1733 MAKEPOINTS (lParam), GetMessageTime());
|
|
1734 msframe->button2_is_down = 1;
|
|
1735 }
|
|
1736 else
|
|
1737 {
|
|
1738 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
1739 msframe->last_click_point, msframe->last_click_time);
|
|
1740 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
1741 MAKEPOINTS (lParam), GetMessageTime());
|
|
1742 }
|
|
1743 }
|
|
1744 else
|
|
1745 {
|
|
1746 mswindows_set_chord_timer (hwnd);
|
|
1747 msframe->button2_need_lbutton = 1;
|
|
1748 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
1749 }
|
|
1750 msframe->last_click_time = GetMessageTime();
|
|
1751 break;
|
|
1752
|
|
1753 case WM_TIMER:
|
|
1754 if (wParam == BUTTON_2_TIMER_ID)
|
|
1755 {
|
|
1756 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1757 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
1758
|
|
1759 if (msframe->button2_need_lbutton)
|
|
1760 {
|
|
1761 msframe->button2_need_lbutton = 0;
|
|
1762 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
1763 msframe->last_click_point, msframe->last_click_time);
|
|
1764 }
|
|
1765 else if (msframe->button2_need_rbutton)
|
|
1766 {
|
|
1767 msframe->button2_need_rbutton = 0;
|
|
1768 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
1769 msframe->last_click_point, msframe->last_click_time);
|
|
1770 }
|
|
1771 }
|
|
1772 else
|
|
1773 assert ("Spurious timer fired" == 0);
|
|
1774 break;
|
|
1775
|
|
1776 case WM_MOUSEMOVE:
|
|
1777 /* Optimization: don't report mouse movement while size is changind */
|
|
1778 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1779 if (!msframe->sizing)
|
|
1780 {
|
|
1781 /* When waiting for the second mouse button to finish
|
|
1782 button2 emulation, and have moved too far, just pretend
|
|
1783 as if timer has expired. This impoves drag-select feedback */
|
|
1784 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
|
|
1785 && !mswindows_button2_near_enough (msframe->last_click_point,
|
|
1786 MAKEPOINTS (lParam)))
|
|
1787 {
|
|
1788 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
1789 SendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
|
|
1790 }
|
|
1791
|
|
1792 emacs_event = Fmake_event (Qnil, Qnil);
|
|
1793 event = XEVENT(emacs_event);
|
|
1794
|
|
1795 event->channel = mswindows_find_frame(hwnd);
|
|
1796 event->timestamp = GetMessageTime();
|
|
1797 event->event_type = pointer_motion_event;
|
|
1798 event->event.motion.x = MAKEPOINTS(lParam).x;
|
|
1799 event->event.motion.y = MAKEPOINTS(lParam).y;
|
|
1800 event->event.motion.modifiers = mswindows_modifier_state (NULL, 0);
|
|
1801
|
|
1802 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1803 }
|
|
1804 break;
|
|
1805
|
278
|
1806 #ifdef HAVE_TOOLBARS
|
|
1807 case WM_NOTIFY:
|
|
1808 {
|
|
1809 LPTOOLTIPTEXT tttext = (LPTOOLTIPTEXT)lParam;
|
|
1810 Lisp_Object btext;
|
|
1811 if (tttext->hdr.code == TTN_NEEDTEXT)
|
|
1812 {
|
|
1813 /* find out which toolbar */
|
|
1814 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
1815 btext = mswindows_get_toolbar_button_text ( frame,
|
|
1816 tttext->hdr.idFrom );
|
|
1817
|
|
1818 tttext->lpszText = NULL;
|
|
1819 tttext->hinst = NULL;
|
|
1820
|
|
1821 if (!NILP(btext))
|
|
1822 {
|
280
|
1823 strncpy (tttext->szText, XSTRING_DATA (btext), XSTRING_LENGTH(btext)+1);
|
278
|
1824 tttext->lpszText=tttext->szText;
|
|
1825 }
|
|
1826 #if 0
|
|
1827 tttext->uFlags |= TTF_DI_SETITEM;
|
|
1828 #endif
|
|
1829 }
|
|
1830 }
|
|
1831 break;
|
|
1832 #endif
|
|
1833
|
249
|
1834 case WM_PAINT:
|
|
1835 {
|
|
1836 PAINTSTRUCT paintStruct;
|
|
1837
|
|
1838 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
1839
|
|
1840 BeginPaint (hwnd, &paintStruct);
|
|
1841 mswindows_redraw_exposed_area (frame,
|
|
1842 paintStruct.rcPaint.left, paintStruct.rcPaint.top,
|
|
1843 paintStruct.rcPaint.right, paintStruct.rcPaint.bottom);
|
|
1844 EndPaint (hwnd, &paintStruct);
|
|
1845 }
|
|
1846 break;
|
|
1847
|
|
1848 case WM_SIZE:
|
|
1849 /* We only care about this message if our size has really changed */
|
|
1850 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
|
|
1851 {
|
|
1852 RECT rect;
|
|
1853 int columns, rows;
|
|
1854
|
|
1855 fobj = mswindows_find_frame (hwnd);
|
|
1856 frame = XFRAME (fobj);
|
|
1857 msframe = FRAME_MSWINDOWS_DATA (frame);
|
|
1858
|
|
1859 /* We cannot handle frame map and unmap hooks right in
|
|
1860 this routine, because these may throw. We queue
|
|
1861 magic events to run these hooks instead - kkm */
|
|
1862
|
|
1863 if (wParam==SIZE_MINIMIZED)
|
|
1864 {
|
|
1865 /* Iconified */
|
269
|
1866 FRAME_VISIBLE_P (frame) = 0;
|
249
|
1867 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
|
1868 }
|
|
1869 else
|
|
1870 {
|
|
1871 GetClientRect(hwnd, &rect);
|
|
1872 FRAME_PIXWIDTH(frame) = rect.right;
|
|
1873 FRAME_PIXHEIGHT(frame) = rect.bottom;
|
269
|
1874
|
|
1875 pixel_to_real_char_size (frame, rect.right, rect.bottom,
|
274
|
1876 &FRAME_MSWINDOWS_CHARWIDTH (frame),
|
|
1877 &FRAME_MSWINDOWS_CHARHEIGHT (frame));
|
269
|
1878
|
249
|
1879 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
|
|
1880 change_frame_size (frame, rows, columns, 1);
|
|
1881
|
269
|
1882 /* If we are inside frame creation, we have to apply geometric
|
|
1883 properties now. */
|
|
1884 if (mswindows_frame_target_rect.left >= 0
|
|
1885 || mswindows_frame_target_rect.top >= 0
|
|
1886 || mswindows_frame_target_rect.width >= 0
|
|
1887 || mswindows_frame_target_rect.height >= 0)
|
|
1888 {
|
|
1889 /* Yes, we have to size again */
|
|
1890 XEMACS_RECT_WH geom;
|
|
1891
|
|
1892 geom.left = mswindows_frame_target_rect.left;
|
|
1893 geom.top = mswindows_frame_target_rect.top;
|
|
1894 char_to_real_pixel_size (frame,
|
|
1895 mswindows_frame_target_rect.width,
|
|
1896 mswindows_frame_target_rect.height,
|
|
1897 &geom.width, &geom.height);
|
|
1898 if (mswindows_frame_target_rect.width < 0)
|
|
1899 geom.width = -1;
|
|
1900 if (mswindows_frame_target_rect.height < 0)
|
|
1901 geom.height = -1;
|
|
1902
|
|
1903 /* Reset to we do not get here again */
|
|
1904 mswindows_frame_target_rect.left = -1;
|
|
1905 mswindows_frame_target_rect.top = -1;
|
|
1906 mswindows_frame_target_rect.width = -1;
|
|
1907 mswindows_frame_target_rect.height = -1;
|
|
1908
|
|
1909 /* Size the rectangle to the actual size */
|
|
1910 GetWindowRect (hwnd, &rect);
|
|
1911 SetWindowPos
|
|
1912 (hwnd, NULL,
|
|
1913 geom.left >= 0 ? geom.left : rect.left,
|
|
1914 geom.top >= 0 ? geom.top : rect.top,
|
|
1915 geom.width >= 0 ? geom.width : rect.right - rect.left,
|
|
1916 geom.height >= 0 ? geom.height : rect.bottom - rect.top,
|
|
1917 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSENDCHANGING
|
|
1918 | ((geom.left >= 0 || geom.top >= 0) ? 0 : SWP_NOMOVE)
|
|
1919 | ((geom.width >= 0 || geom.height >= 0) ? 0 : SWP_NOSIZE));
|
|
1920 }
|
|
1921 else
|
|
1922 {
|
|
1923 if (!msframe->sizing && !FRAME_VISIBLE_P (frame))
|
|
1924 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
1925 FRAME_VISIBLE_P (frame) = 1;
|
|
1926
|
|
1927 if (!msframe->sizing || mswindows_dynamic_frame_resize)
|
|
1928 redisplay ();
|
|
1929 }
|
249
|
1930 }
|
|
1931 }
|
|
1932 break;
|
|
1933
|
|
1934 /* Misc magic events which only require that the frame be identified */
|
|
1935 case WM_SETFOCUS:
|
|
1936 case WM_KILLFOCUS:
|
|
1937 mswindows_enqueue_magic_event (hwnd, message);
|
|
1938 break;
|
|
1939
|
|
1940 case WM_WINDOWPOSCHANGING:
|
|
1941 {
|
|
1942 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
|
|
1943 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
|
|
1944 GetWindowPlacement(hwnd, &wpl);
|
|
1945
|
|
1946 /* Only interested if size is changing and we're not being iconified */
|
269
|
1947 if (wpl.showCmd != SW_SHOWMINIMIZED
|
|
1948 && wpl.showCmd != SW_SHOWMAXIMIZED
|
|
1949 && !(wp->flags & SWP_NOSIZE))
|
249
|
1950 {
|
|
1951 RECT ncsize = { 0, 0, 0, 0 };
|
|
1952 int pixwidth, pixheight;
|
|
1953 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
|
|
1954 GetMenu(hwnd) != NULL,
|
|
1955 GetWindowLong (hwnd, GWL_EXSTYLE));
|
|
1956
|
269
|
1957 round_size_to_real_char (XFRAME (mswindows_find_frame (hwnd)),
|
|
1958 wp->cx - (ncsize.right - ncsize.left),
|
|
1959 wp->cy - (ncsize.bottom - ncsize.top),
|
|
1960 &pixwidth, &pixheight);
|
249
|
1961
|
|
1962 /* Convert client sizes to window sizes */
|
|
1963 pixwidth += (ncsize.right - ncsize.left);
|
|
1964 pixheight += (ncsize.bottom - ncsize.top);
|
|
1965
|
|
1966 if (wpl.showCmd != SW_SHOWMAXIMIZED)
|
|
1967 {
|
|
1968 /* Adjust so that the bottom or right doesn't move if it's
|
|
1969 * the top or left that's being changed */
|
|
1970 RECT rect;
|
|
1971 GetWindowRect (hwnd, &rect);
|
|
1972
|
|
1973 if (rect.left != wp->x)
|
|
1974 wp->x += wp->cx - pixwidth;
|
|
1975 if (rect.top != wp->y)
|
|
1976 wp->y += wp->cy - pixheight;
|
|
1977 }
|
|
1978
|
|
1979 wp->cx = pixwidth;
|
|
1980 wp->cy = pixheight;
|
|
1981 }
|
269
|
1982 /* DefWindowProc sends useful WM_GETMINMAXINFO message, and adjusts
|
|
1983 window position if the user tries to track window too small */
|
249
|
1984 }
|
269
|
1985 goto defproc;
|
249
|
1986
|
|
1987 case WM_ENTERSIZEMOVE:
|
|
1988 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1989 msframe->sizing = 1;
|
|
1990 return 0;
|
|
1991
|
|
1992 case WM_EXITSIZEMOVE:
|
|
1993 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1994 msframe->sizing = 0;
|
|
1995 /* Queue noop event */
|
276
|
1996 mswindows_bump_queue ();
|
249
|
1997 return 0;
|
|
1998
|
|
1999 #ifdef HAVE_SCROLLBARS
|
|
2000 case WM_VSCROLL:
|
|
2001 case WM_HSCROLL:
|
|
2002 {
|
|
2003 /* Direction of scroll is determined by scrollbar instance. */
|
|
2004 int code = (int) LOWORD(wParam);
|
|
2005 int pos = (short int) HIWORD(wParam);
|
|
2006 HWND hwndScrollBar = (HWND) lParam;
|
|
2007 struct gcpro gcpro1, gcpro2;
|
|
2008
|
|
2009 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
|
|
2010 GCPRO2 (emacs_event, fobj);
|
|
2011 if (UNBOUNDP(mswindows_pump_outstanding_events())) /* Can GC */
|
|
2012 {
|
|
2013 /* Error during event pumping - cancel scroll */
|
|
2014 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
|
|
2015 }
|
|
2016 UNGCPRO;
|
|
2017 break;
|
|
2018 }
|
|
2019 #endif
|
|
2020
|
|
2021 #ifdef HAVE_MENUBARS
|
|
2022 case WM_INITMENU:
|
|
2023 if (UNBOUNDP (mswindows_handle_wm_initmenu (
|
|
2024 (HMENU) wParam,
|
|
2025 XFRAME (mswindows_find_frame (hwnd)))))
|
|
2026 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
2027 break;
|
|
2028
|
|
2029 case WM_INITMENUPOPUP:
|
|
2030 if (!HIWORD(lParam))
|
|
2031 {
|
|
2032 if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
|
|
2033 (HMENU) wParam,
|
|
2034 XFRAME (mswindows_find_frame (hwnd)))))
|
|
2035 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
2036 }
|
|
2037 break;
|
|
2038
|
|
2039 #endif /* HAVE_MENUBARS */
|
|
2040
|
|
2041 case WM_COMMAND:
|
|
2042 {
|
|
2043 WORD id = LOWORD (wParam);
|
278
|
2044 HWND cid = (HWND)lParam;
|
249
|
2045 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
2046
|
276
|
2047 #ifdef HAVE_TOOLBARS
|
278
|
2048 if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
|
276
|
2049 break;
|
|
2050 #endif
|
|
2051
|
249
|
2052 #ifdef HAVE_MENUBARS
|
|
2053 if (!NILP (mswindows_handle_wm_command (frame, id)))
|
|
2054 break;
|
|
2055 #endif
|
|
2056
|
269
|
2057 /* Bite me - a spurious command. This cannot happen. */
|
|
2058 error ("XEMACS BUG: Cannot decode command message");
|
249
|
2059 }
|
|
2060 break;
|
|
2061
|
|
2062 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
|
|
2063 {
|
|
2064 UINT filecount, i, len;
|
|
2065 POINT point;
|
282
|
2066 char* filename;
|
259
|
2067 #ifdef __CYGWIN32__
|
|
2068 char* fname;
|
|
2069 #endif
|
282
|
2070 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
|
|
2071 struct gcpro gcpro1, gcpro2, gcpro3;
|
249
|
2072
|
|
2073 emacs_event = Fmake_event (Qnil, Qnil);
|
|
2074 event = XEVENT(emacs_event);
|
|
2075
|
282
|
2076 GCPRO3 (emacs_event, l_dndlist, l_item);
|
|
2077
|
249
|
2078 if (!DragQueryPoint ((HANDLE) wParam, &point))
|
|
2079 point.x = point.y = -1; /* outside client area */
|
|
2080
|
282
|
2081 event->event_type = misc_user_event;
|
|
2082 event->channel = mswindows_find_frame(hwnd);
|
|
2083 event->timestamp = GetMessageTime();
|
|
2084 event->event.misc.button = 1; /* #### Should try harder */
|
|
2085 event->event.misc.modifiers = mswindows_modifier_state (NULL, 0);
|
|
2086 event->event.misc.x = point.x;
|
|
2087 event->event.misc.y = point.y;
|
|
2088 event->event.misc.function = Qdragdrop_drop_dispatch;
|
|
2089
|
|
2090 filecount = DragQueryFile ((HANDLE) wParam, 0xffffffff, NULL, 0);
|
|
2091 for (i=0; i<filecount; i++)
|
249
|
2092 {
|
282
|
2093 len = DragQueryFile ((HANDLE) wParam, i, NULL, 0);
|
|
2094 /* The URLs that we make here aren't correct according to section
|
|
2095 * 3.10 of rfc1738 because they're missing the //<host>/ part and
|
|
2096 * because they may contain reserved characters. But that's OK. */
|
259
|
2097 #ifdef __CYGWIN32__
|
282
|
2098 fname = (char *)xmalloc (len+1);
|
|
2099 DragQueryFile ((HANDLE) wParam, i, fname, len+1);
|
|
2100 filename = xmalloc (cygwin32_win32_to_posix_path_list_buf_size (fname) + 5);
|
|
2101 strcpy (filename, "file:");
|
|
2102 cygwin32_win32_to_posix_path_list (fname, filename+5);
|
|
2103 xfree (fname);
|
259
|
2104 #else
|
282
|
2105 filename = (char *)xmalloc (len+6);
|
|
2106 strcpy (filename, "file:");
|
|
2107 DragQueryFile ((HANDLE) wParam, i, filename+5, len+1);
|
|
2108 dostounix_filename (filename+5);
|
259
|
2109 #endif
|
282
|
2110 l_item = make_string (filename, strlen (filename));
|
|
2111 l_dndlist = Fcons (l_item, l_dndlist);
|
|
2112 xfree (filename);
|
249
|
2113 }
|
|
2114 DragFinish ((HANDLE) wParam);
|
|
2115
|
282
|
2116 event->event.misc.object = Fcons (Qdragdrop_URL, l_dndlist);
|
249
|
2117 mswindows_enqueue_dispatch_event (emacs_event);
|
282
|
2118 UNGCPRO;
|
249
|
2119 }
|
|
2120 break;
|
|
2121
|
282
|
2122
|
249
|
2123 defproc:
|
|
2124 default:
|
|
2125 return DefWindowProc (hwnd, message, wParam, lParam);
|
|
2126 }
|
|
2127 return (0);
|
|
2128 }
|
|
2129
|
|
2130
|
|
2131 /************************************************************************/
|
|
2132 /* keyboard, mouse & other helpers for the windows procedure */
|
|
2133 /************************************************************************/
|
|
2134 static void
|
|
2135 mswindows_set_chord_timer (HWND hwnd)
|
|
2136 {
|
|
2137 int interval;
|
|
2138
|
269
|
2139 /* We get one third half system double click threshold */
|
272
|
2140 if (mswindows_mouse_button_tolerance <= 0)
|
269
|
2141 interval = GetDoubleClickTime () / 3;
|
249
|
2142 else
|
272
|
2143 interval = mswindows_mouse_button_tolerance;
|
249
|
2144
|
|
2145 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
2146 }
|
|
2147
|
|
2148 static int
|
|
2149 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
2150 {
|
|
2151 int dx, dy;
|
272
|
2152 if (mswindows_mouse_button_max_skew_x <= 0)
|
249
|
2153 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
2154 else
|
272
|
2155 dx = mswindows_mouse_button_max_skew_x;
|
249
|
2156
|
272
|
2157 if (mswindows_mouse_button_max_skew_y <= 0)
|
249
|
2158 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
2159 else
|
272
|
2160 dy = mswindows_mouse_button_max_skew_y;
|
249
|
2161
|
|
2162 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
2163 }
|
|
2164
|
|
2165 static int
|
|
2166 mswindows_current_layout_has_AltGr (void)
|
|
2167 {
|
|
2168 /* This simple caching mechanism saves 10% of CPU
|
|
2169 time when a key typed at autorepeat rate of 30 cps! */
|
|
2170 static HKL last_hkl = 0;
|
|
2171 static int last_hkl_has_AltGr;
|
|
2172
|
|
2173 HKL current_hkl = GetKeyboardLayout (0);
|
|
2174 if (current_hkl != last_hkl)
|
|
2175 {
|
|
2176 TCHAR c;
|
|
2177 last_hkl_has_AltGr = 0;
|
|
2178 /* In this loop, we query whether a character requires
|
|
2179 AltGr to be down to generate it. If at least such one
|
|
2180 found, this means that the layout does regard AltGr */
|
|
2181 for (c = ' '; c <= 0xFFU && c != 0 && !last_hkl_has_AltGr; ++c)
|
|
2182 if (HIBYTE (VkKeyScan (c)) == 6)
|
|
2183 last_hkl_has_AltGr = 1;
|
|
2184 last_hkl = current_hkl;
|
|
2185 }
|
|
2186 return last_hkl_has_AltGr;
|
|
2187 }
|
|
2188
|
|
2189
|
|
2190 /* Returns the state of the modifier keys in the format expected by the
|
|
2191 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
|
2192 int mswindows_modifier_state (BYTE* keymap, int has_AltGr)
|
|
2193 {
|
|
2194 int mods = 0;
|
|
2195
|
|
2196 if (keymap == NULL)
|
|
2197 {
|
|
2198 keymap = (BYTE*) alloca(256);
|
|
2199 GetKeyboardState (keymap);
|
|
2200 has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
2201 }
|
|
2202
|
|
2203 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
|
|
2204 {
|
|
2205 mods |= (keymap [VK_LMENU] & 0x80) ? MOD_META : 0;
|
|
2206 mods |= (keymap [VK_RCONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
2207 }
|
|
2208 else
|
|
2209 {
|
|
2210 mods |= (keymap [VK_MENU] & 0x80) ? MOD_META : 0;
|
|
2211 mods |= (keymap [VK_CONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
2212 }
|
|
2213
|
|
2214 mods |= (keymap [VK_SHIFT] & 0x80) ? MOD_SHIFT : 0;
|
|
2215
|
|
2216 return mods;
|
|
2217 }
|
|
2218
|
|
2219 /*
|
|
2220 * Translate a mswindows virtual key to a keysym.
|
|
2221 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
2222 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
2223 * Virtual key values are defined in winresrc.h
|
|
2224 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
|
|
2225 */
|
|
2226 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods)
|
|
2227 {
|
|
2228 switch (mswindows_key)
|
|
2229 {
|
|
2230 /* First the predefined ones */
|
|
2231 case VK_BACK: return QKbackspace;
|
|
2232 case VK_TAB: return QKtab;
|
|
2233 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */
|
|
2234 case VK_RETURN: return QKreturn;
|
|
2235 case VK_ESCAPE: return QKescape;
|
|
2236 case VK_SPACE: return QKspace;
|
|
2237 case VK_DELETE: return QKdelete;
|
|
2238
|
|
2239 /* The rest */
|
|
2240 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */
|
|
2241 case VK_PRIOR: return KEYSYM ("prior");
|
|
2242 case VK_NEXT: return KEYSYM ("next");
|
|
2243 case VK_END: return KEYSYM ("end");
|
|
2244 case VK_HOME: return KEYSYM ("home");
|
|
2245 case VK_LEFT: return KEYSYM ("left");
|
|
2246 case VK_UP: return KEYSYM ("up");
|
|
2247 case VK_RIGHT: return KEYSYM ("right");
|
|
2248 case VK_DOWN: return KEYSYM ("down");
|
|
2249 case VK_SELECT: return KEYSYM ("select");
|
|
2250 case VK_PRINT: return KEYSYM ("print");
|
|
2251 case VK_EXECUTE: return KEYSYM ("execute");
|
|
2252 case VK_SNAPSHOT: return KEYSYM ("print");
|
|
2253 case VK_INSERT: return KEYSYM ("insert");
|
|
2254 case VK_HELP: return KEYSYM ("help");
|
|
2255 #if 0 /* XXX What are these supposed to do? */
|
|
2256 case VK_LWIN return KEYSYM ("");
|
|
2257 case VK_RWIN return KEYSYM ("");
|
|
2258 #endif
|
|
2259 case VK_APPS: return KEYSYM ("menu");
|
|
2260 case VK_F1: return KEYSYM ("f1");
|
|
2261 case VK_F2: return KEYSYM ("f2");
|
|
2262 case VK_F3: return KEYSYM ("f3");
|
|
2263 case VK_F4: return KEYSYM ("f4");
|
|
2264 case VK_F5: return KEYSYM ("f5");
|
|
2265 case VK_F6: return KEYSYM ("f6");
|
|
2266 case VK_F7: return KEYSYM ("f7");
|
|
2267 case VK_F8: return KEYSYM ("f8");
|
|
2268 case VK_F9: return KEYSYM ("f9");
|
|
2269 case VK_F10: return KEYSYM ("f10");
|
|
2270 case VK_F11: return KEYSYM ("f11");
|
|
2271 case VK_F12: return KEYSYM ("f12");
|
|
2272 case VK_F13: return KEYSYM ("f13");
|
|
2273 case VK_F14: return KEYSYM ("f14");
|
|
2274 case VK_F15: return KEYSYM ("f15");
|
|
2275 case VK_F16: return KEYSYM ("f16");
|
|
2276 case VK_F17: return KEYSYM ("f17");
|
|
2277 case VK_F18: return KEYSYM ("f18");
|
|
2278 case VK_F19: return KEYSYM ("f19");
|
|
2279 case VK_F20: return KEYSYM ("f20");
|
|
2280 case VK_F21: return KEYSYM ("f21");
|
|
2281 case VK_F22: return KEYSYM ("f22");
|
|
2282 case VK_F23: return KEYSYM ("f23");
|
|
2283 case VK_F24: return KEYSYM ("f24");
|
|
2284 }
|
|
2285 return Qnil;
|
|
2286 }
|
|
2287
|
|
2288 /*
|
|
2289 * Find the console that matches the supplied mswindows window handle
|
|
2290 */
|
|
2291 Lisp_Object
|
|
2292 mswindows_find_console (HWND hwnd)
|
|
2293 {
|
274
|
2294 /* We only support one console */
|
|
2295 return XCAR (Vconsole_list);
|
249
|
2296 }
|
|
2297
|
|
2298 /*
|
|
2299 * Find the frame that matches the supplied mswindows window handle
|
|
2300 */
|
|
2301 static Lisp_Object
|
|
2302 mswindows_find_frame (HWND hwnd)
|
|
2303 {
|
269
|
2304 LONG l = GetWindowLong (hwnd, XWL_FRAMEOBJ);
|
|
2305 Lisp_Object f;
|
|
2306 if (l == 0)
|
|
2307 {
|
|
2308 /* We are in progress of frame creation. Return the frame
|
|
2309 being created, as it still not remembered in the window
|
|
2310 extra storage. */
|
276
|
2311 assert (!NILP (Vmswindows_frame_being_created));
|
|
2312 return Vmswindows_frame_being_created;
|
269
|
2313 }
|
|
2314 VOID_TO_LISP (f, l);
|
|
2315 return f;
|
249
|
2316 }
|
|
2317
|
213
|
2318
|
|
2319 /************************************************************************/
|
|
2320 /* methods */
|
|
2321 /************************************************************************/
|
|
2322
|
|
2323 static int
|
|
2324 emacs_mswindows_add_timeout (EMACS_TIME thyme)
|
|
2325 {
|
223
|
2326 int milliseconds;
|
213
|
2327 EMACS_TIME current_time;
|
|
2328 EMACS_GET_TIME (current_time);
|
|
2329 EMACS_SUB_TIME (thyme, thyme, current_time);
|
223
|
2330 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
2331 (EMACS_USECS (thyme) + 500) / 1000;
|
213
|
2332 if (milliseconds < 1)
|
|
2333 milliseconds = 1;
|
227
|
2334 ++mswindows_pending_timers_count;
|
249
|
2335 return SetTimer (NULL, 0, milliseconds,
|
|
2336 (TIMERPROC) mswindows_wm_timer_callback);
|
213
|
2337 }
|
|
2338
|
|
2339 static void
|
|
2340 emacs_mswindows_remove_timeout (int id)
|
|
2341 {
|
223
|
2342 struct Lisp_Event match_against;
|
|
2343 Lisp_Object emacs_event;
|
|
2344
|
233
|
2345 if (KillTimer (NULL, id))
|
|
2346 --mswindows_pending_timers_count;
|
223
|
2347
|
|
2348 /* If there is a dispatch event generated by this
|
|
2349 timeout in the queue, we have to remove it too. */
|
|
2350 match_against.event_type = timeout_event;
|
|
2351 match_against.event.timeout.interval_id = id;
|
|
2352 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
2353 if (!NILP (emacs_event))
|
|
2354 Fdeallocate_event(emacs_event);
|
213
|
2355 }
|
|
2356
|
219
|
2357 /* If `user_p' is false, then return whether there are any win32, timeout,
|
|
2358 * or subprocess events pending (that is, whether
|
|
2359 * emacs_mswindows_next_event() would return immediately without blocking).
|
|
2360 *
|
|
2361 * if `user_p' is true, then return whether there are any *user generated*
|
|
2362 * events available (that is, whether there are keyboard or mouse-click
|
|
2363 * events ready to be read). This also implies that
|
|
2364 * emacs_mswindows_next_event() would not block.
|
|
2365 */
|
213
|
2366 static int
|
|
2367 emacs_mswindows_event_pending_p (int user_p)
|
|
2368 {
|
274
|
2369 mswindows_need_event (0);
|
223
|
2370 return (!NILP (mswindows_u_dispatch_event_queue)
|
|
2371 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
|
213
|
2372 }
|
|
2373
|
|
2374 /*
|
|
2375 * Return the next event
|
|
2376 */
|
|
2377 static void
|
|
2378 emacs_mswindows_next_event (struct Lisp_Event *emacs_event)
|
|
2379 {
|
223
|
2380 Lisp_Object event, event2;
|
|
2381
|
274
|
2382 mswindows_need_event (1);
|
213
|
2383
|
223
|
2384 event = mswindows_dequeue_dispatch_event (!NILP(mswindows_u_dispatch_event_queue));
|
|
2385 XSETEVENT (event2, emacs_event);
|
|
2386 Fcopy_event (event, event2);
|
|
2387 Fdeallocate_event (event);
|
213
|
2388 }
|
|
2389
|
|
2390 /*
|
|
2391 * Handle a magic event off the dispatch queue.
|
|
2392 */
|
|
2393 static void
|
|
2394 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event)
|
|
2395 {
|
|
2396 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
|
|
2397 {
|
|
2398 case WM_SETFOCUS:
|
|
2399 case WM_KILLFOCUS:
|
|
2400 {
|
223
|
2401 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
2402 struct frame *f = XFRAME (frame);
|
213
|
2403 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
|
|
2404 Lisp_Object conser;
|
223
|
2405
|
213
|
2406 /* struct gcpro gcpro1; */
|
|
2407
|
|
2408 /* Clear sticky modifiers here (if we had any) */
|
|
2409
|
|
2410 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
2411 /* GCPRO1 (conser); XXX Not necessary? */
|
|
2412 emacs_handle_focus_change_preliminary (conser);
|
|
2413 /* Under X the stuff up to here is done in the X event handler.
|
|
2414 I Don't know why */
|
|
2415 emacs_handle_focus_change_final (conser);
|
|
2416 /* UNGCPRO; */
|
223
|
2417
|
213
|
2418 }
|
|
2419 break;
|
|
2420
|
223
|
2421 case XM_MAPFRAME:
|
|
2422 case XM_UNMAPFRAME:
|
|
2423 {
|
|
2424 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
2425 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
|
|
2426 == XM_MAPFRAME ?
|
|
2427 Qmap_frame_hook : Qunmap_frame_hook,
|
|
2428 1, frame);
|
|
2429 }
|
|
2430 break;
|
|
2431
|
249
|
2432 /* #### What about Enter & Leave */
|
213
|
2433 #if 0
|
|
2434 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
|
|
2435 Qmouse_leave_frame_hook, 1, frame);
|
|
2436 #endif
|
|
2437
|
|
2438 default:
|
|
2439 assert(0);
|
|
2440 }
|
|
2441 }
|
|
2442
|
274
|
2443 static HANDLE
|
|
2444 get_process_input_waitable (struct Lisp_Process *process)
|
|
2445 {
|
282
|
2446 Lisp_Object instr, outstr, p;
|
|
2447 XSETPROCESS (p, process);
|
274
|
2448 get_process_streams (process, &instr, &outstr);
|
|
2449 assert (!NILP (instr));
|
282
|
2450 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
2451 return (network_connection_p (p)
|
|
2452 ? get_winsock_stream_waitable (XLSTREAM (instr))
|
|
2453 : get_ntpipe_input_stream_waitable (XLSTREAM (instr)));
|
|
2454 #else
|
|
2455 return get_ntpipe_input_stream_waitable (XLSTREAM (instr));
|
|
2456 #endif
|
274
|
2457 }
|
|
2458
|
213
|
2459 static void
|
|
2460 emacs_mswindows_select_process (struct Lisp_Process *process)
|
|
2461 {
|
274
|
2462 HANDLE hev = get_process_input_waitable (process);
|
|
2463
|
|
2464 if (!add_waitable_handle (hev))
|
|
2465 error ("Too many active processes");
|
|
2466
|
276
|
2467 #ifdef HAVE_WIN32_PROCESSES
|
|
2468 {
|
282
|
2469 Lisp_Object p;
|
|
2470 XSETPROCESS (p, process);
|
|
2471 if (!network_connection_p (p))
|
276
|
2472 {
|
282
|
2473 HANDLE hprocess = get_nt_process_handle (process);
|
|
2474 if (!add_waitable_handle (hprocess))
|
|
2475 {
|
|
2476 remove_waitable_handle (hev);
|
|
2477 error ("Too many active processes");
|
|
2478 }
|
276
|
2479 }
|
|
2480 }
|
|
2481 #endif
|
213
|
2482 }
|
|
2483
|
|
2484 static void
|
|
2485 emacs_mswindows_unselect_process (struct Lisp_Process *process)
|
|
2486 {
|
274
|
2487 /* Process handle is removed in the event loop as soon
|
|
2488 as it is signaled, so don't bother here about it */
|
|
2489 HANDLE hev = get_process_input_waitable (process);
|
|
2490 remove_waitable_handle (hev);
|
213
|
2491 }
|
|
2492
|
|
2493 static void
|
|
2494 emacs_mswindows_select_console (struct console *con)
|
|
2495 {
|
|
2496 }
|
|
2497
|
|
2498 static void
|
|
2499 emacs_mswindows_unselect_console (struct console *con)
|
|
2500 {
|
|
2501 }
|
|
2502
|
|
2503 static void
|
|
2504 emacs_mswindows_quit_p (void)
|
|
2505 {
|
276
|
2506 /* Quit cannot happen in modal loop: all program
|
|
2507 input is dedicated to Windows. */
|
|
2508 if (mswindows_in_modal_loop)
|
|
2509 return;
|
|
2510
|
274
|
2511 /* Drain windows queue. This sets up number of quit
|
|
2512 characters in in the queue */
|
|
2513 mswindows_drain_windows_queue ();
|
223
|
2514
|
|
2515 if (mswindows_quit_chars_count > 0)
|
|
2516 {
|
|
2517 /* Yes there's a hidden one... Throw it away */
|
|
2518 struct Lisp_Event match_against;
|
|
2519 Lisp_Object emacs_event;
|
|
2520
|
|
2521 match_against.event_type = key_press_event;
|
|
2522 match_against.event.key.modifiers = FAKE_MOD_QUIT;
|
|
2523
|
|
2524 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
2525 assert (!NILP (emacs_event));
|
|
2526
|
|
2527 Vquit_flag = (XEVENT(emacs_event)->event.key.modifiers & MOD_SHIFT
|
|
2528 ? Qcritical : Qt);
|
|
2529
|
|
2530 Fdeallocate_event(emacs_event);
|
|
2531 --mswindows_quit_chars_count;
|
|
2532 }
|
213
|
2533 }
|
|
2534
|
274
|
2535 USID
|
|
2536 emacs_mswindows_create_stream_pair (void* inhandle, void* outhandle,
|
|
2537 Lisp_Object* instream,
|
|
2538 Lisp_Object* outstream,
|
|
2539 int flags)
|
|
2540 {
|
|
2541 /* Handles for streams */
|
|
2542 HANDLE hin, hout;
|
|
2543 /* fds. These just stored along with the streams, and are closed in
|
|
2544 delete stream pair method, because we need to handle fake unices
|
|
2545 here. */
|
|
2546 int fdi, fdo;
|
|
2547
|
|
2548 /* Decode inhandle and outhandle. Their meaning depends on
|
|
2549 the process implementation being used. */
|
|
2550 #if defined (HAVE_WIN32_PROCESSES)
|
|
2551 /* We're passed in Windows handles. That's what we like most... */
|
|
2552 hin = (HANDLE) inhandle;
|
|
2553 hout = (HANDLE) outhandle;
|
|
2554 fdi = fdo = -1;
|
|
2555 #elif defined (HAVE_UNIX_PROCESSES)
|
|
2556 /* We are passed UNIX fds. This must be Cygwin.
|
|
2557 Fetch os handles */
|
276
|
2558 hin = inhandle >= 0 ? (HANDLE)get_osfhandle ((int)inhandle) : INVALID_HANDLE_VALUE;
|
|
2559 hout = outhandle >= 0 ? (HANDLE)get_osfhandle ((int)outhandle) : INVALID_HANDLE_VALUE;
|
|
2560 fdi=(int)inhandle;
|
|
2561 fdo=(int)outhandle;
|
274
|
2562 #else
|
|
2563 #error "So, WHICH kind of processes do you want?"
|
|
2564 #endif
|
|
2565
|
282
|
2566 *instream = (hin == INVALID_HANDLE_VALUE
|
|
2567 ? Qnil
|
|
2568 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
|
|
2569 : flags & STREAM_NETWORK_CONNECTION
|
|
2570 ? make_winsock_input_stream ((SOCKET)hin, fdi)
|
|
2571 #endif
|
|
2572 : make_ntpipe_input_stream (hin, fdi));
|
274
|
2573
|
276
|
2574 #ifdef HAVE_WIN32_PROCESSES
|
282
|
2575 *outstream = (hout == INVALID_HANDLE_VALUE
|
|
2576 ? Qnil
|
|
2577 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
|
|
2578 : flags & STREAM_NETWORK_CONNECTION
|
|
2579 ? make_winsock_output_stream ((SOCKET)hout, fdo)
|
|
2580 #endif
|
|
2581 : make_ntpipe_output_stream (hout, fdo));
|
276
|
2582 #elif defined (HAVE_UNIX_PROCESSES)
|
|
2583 *outstream = (fdo >= 0
|
|
2584 ? make_filedesc_output_stream (fdo, 0, -1, LSTR_BLOCKED_OK)
|
|
2585 : Qnil);
|
|
2586
|
|
2587 #if defined(HAVE_UNIX_PROCESSES) && defined(HAVE_PTYS)
|
|
2588 /* FLAGS is process->pty_flag for UNIX_PROCESSES */
|
282
|
2589 if ((flags & STREAM_PTY_FLUSHING) && fdo >= 0)
|
276
|
2590 {
|
|
2591 Bufbyte eof_char = get_eof_char (fdo);
|
|
2592 int pty_max_bytes = get_pty_max_bytes (fdo);
|
|
2593 filedesc_stream_set_pty_flushing (XLSTREAM(*outstream), pty_max_bytes, eof_char);
|
|
2594 }
|
|
2595 #endif
|
|
2596 #endif
|
274
|
2597
|
282
|
2598 return (NILP (*instream)
|
|
2599 ? USID_ERROR
|
|
2600 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
2601 : flags & STREAM_NETWORK_CONNECTION
|
|
2602 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream)))
|
|
2603 #endif
|
274
|
2604 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (*instream))));
|
|
2605 }
|
|
2606
|
|
2607 USID
|
|
2608 emacs_mswindows_delete_stream_pair (Lisp_Object instream,
|
|
2609 Lisp_Object outstream)
|
|
2610 {
|
|
2611 /* Oh nothing special here for Win32 at all */
|
|
2612 #if defined (HAVE_UNIX_PROCESSES)
|
282
|
2613 int in = (NILP(instream)
|
|
2614 ? -1
|
|
2615 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
2616 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
|
|
2617 ? get_winsock_stream_param (XLSTREAM (instream))
|
|
2618 #endif
|
274
|
2619 : get_ntpipe_input_stream_param (XLSTREAM (instream)));
|
|
2620 int out = (NILP(outstream) ? -1
|
276
|
2621 : filedesc_stream_fd (XLSTREAM (outstream)));
|
274
|
2622
|
|
2623 if (in >= 0)
|
|
2624 close (in);
|
|
2625 if (out != in && out >= 0)
|
|
2626 close (out);
|
|
2627 #endif
|
|
2628
|
282
|
2629 return (NILP (instream)
|
|
2630 ? USID_DONTHASH
|
|
2631 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
2632 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
|
|
2633 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
|
|
2634 #endif
|
274
|
2635 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (instream))));
|
|
2636 }
|
|
2637
|
263
|
2638 #ifndef HAVE_X_WINDOWS
|
213
|
2639 /* This is called from GC when a process object is about to be freed.
|
|
2640 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
2641 */
|
|
2642 void
|
|
2643 debug_process_finalization (struct Lisp_Process *p)
|
|
2644 {
|
|
2645 #if 0 /* #### */
|
263
|
2646 Lisp_Object instr, outstr;
|
|
2647
|
|
2648 get_process_streams (p, &instr, &outstr);
|
213
|
2649 /* if it still has fds, then it hasn't been killed yet. */
|
263
|
2650 assert (NILP(instr));
|
|
2651 assert (NILP(outstr));
|
|
2652
|
|
2653 /* #### More checks here */
|
213
|
2654 #endif
|
|
2655 }
|
263
|
2656 #endif
|
213
|
2657
|
|
2658 /************************************************************************/
|
|
2659 /* initialization */
|
|
2660 /************************************************************************/
|
|
2661
|
|
2662 void
|
|
2663 vars_of_event_mswindows (void)
|
|
2664 {
|
223
|
2665 mswindows_u_dispatch_event_queue = Qnil;
|
|
2666 staticpro (&mswindows_u_dispatch_event_queue);
|
|
2667 mswindows_u_dispatch_event_queue_tail = Qnil;
|
|
2668
|
|
2669 mswindows_s_dispatch_event_queue = Qnil;
|
|
2670 staticpro (&mswindows_s_dispatch_event_queue);
|
|
2671 mswindows_s_dispatch_event_queue_tail = Qnil;
|
213
|
2672
|
231
|
2673 mswindows_error_caught_in_modal_loop = Qnil;
|
|
2674 staticpro (&mswindows_error_caught_in_modal_loop);
|
|
2675 mswindows_in_modal_loop = 0;
|
227
|
2676 mswindows_pending_timers_count = 0;
|
|
2677
|
213
|
2678 mswindows_event_stream = xnew (struct event_stream);
|
|
2679
|
|
2680 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
|
223
|
2681 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
|
213
|
2682 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
|
|
2683 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
|
|
2684 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
|
278
|
2685 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
|
213
|
2686 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
|
223
|
2687 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
|
278
|
2688 #ifdef HAVE_MSG_SELECT
|
|
2689 mswindows_event_stream->select_process_cb =
|
|
2690 (void (*)(struct Lisp_Process*))event_stream_unixoid_select_process;
|
|
2691 mswindows_event_stream->unselect_process_cb =
|
|
2692 (void (*)(struct Lisp_Process*))event_stream_unixoid_unselect_process;
|
|
2693 mswindows_event_stream->create_stream_pair_cb = event_stream_unixoid_create_stream_pair;
|
|
2694 mswindows_event_stream->delete_stream_pair_cb = event_stream_unixoid_delete_stream_pair;
|
|
2695 #else
|
213
|
2696 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
|
223
|
2697 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
|
274
|
2698 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair;
|
|
2699 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair;
|
278
|
2700 #endif
|
223
|
2701
|
225
|
2702 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
|
223
|
2703 *Controls redrawing frame contents during mouse-drag or keyboard resize
|
|
2704 operation. When non-nil, the frame is redrawn while being resized. When
|
|
2705 nil, frame is not redrawn, and exposed areas are filled with default
|
|
2706 MDI application background color. Note that this option only has effect
|
|
2707 if "Show window contents while dragging" is on in system Display/Plus!
|
|
2708 settings.
|
|
2709 Default is t on fast machines, nil on slow.
|
|
2710 */ );
|
|
2711
|
|
2712 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
272
|
2713 DEFVAR_INT ("mswindows-mouse-button-tolerance", &mswindows_mouse_button_tolerance /*
|
223
|
2714 *Analogue of double click interval for faking middle mouse events.
|
|
2715 The value is the minimum time in milliseconds that must elapse between
|
|
2716 left/right button down events before they are considered distinct events.
|
|
2717 If both mouse buttons are depressed within this interval, a middle mouse
|
|
2718 button down event is generated instead.
|
|
2719 If negative or zero, currently set system default is used instead.
|
|
2720 */ );
|
|
2721
|
|
2722 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
2723 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
|
223
|
2724 Number of physical mouse buttons.
|
|
2725 */ );
|
|
2726
|
272
|
2727 DEFVAR_INT ("mswindows-mouse-button-max-skew-x", &mswindows_mouse_button_max_skew_x /*
|
223
|
2728 *Maximum horizontal distance in pixels between points in which left and
|
|
2729 right button clicks occured for them to be translated into single
|
|
2730 middle button event. Clicks must occur in time not longer than defined
|
272
|
2731 by the variable `mswindows-mouse-button-tolerance'.
|
223
|
2732 If negative or zero, currently set system default is used instead.
|
|
2733 */ );
|
|
2734
|
272
|
2735 DEFVAR_INT ("mswindows-mouse-button-max-skew-y", &mswindows_mouse_button_max_skew_y /*
|
223
|
2736 *Maximum vertical distance in pixels between points in which left and
|
|
2737 right button clicks occured for them to be translated into single
|
|
2738 middle button event. Clicks must occur in time not longer than defined
|
272
|
2739 by the variable `mswindows-mouse-button-tolerance'.
|
223
|
2740 If negative or zero, currently set system default is used instead.
|
|
2741 */ );
|
|
2742
|
272
|
2743 mswindows_mouse_button_max_skew_x = 0;
|
|
2744 mswindows_mouse_button_max_skew_y = 0;
|
|
2745 mswindows_mouse_button_tolerance = 0;
|
213
|
2746 }
|
|
2747
|
|
2748 void
|
|
2749 syms_of_event_mswindows (void)
|
|
2750 {
|
|
2751 }
|
|
2752
|
|
2753 void
|
274
|
2754 lstream_type_create_mswindows_selectable (void)
|
|
2755 {
|
|
2756 init_slurp_stream ();
|
|
2757 init_shove_stream ();
|
282
|
2758 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
2759 init_winsock_stream ();
|
|
2760 #endif
|
274
|
2761 }
|
|
2762
|
|
2763 void
|
213
|
2764 init_event_mswindows_late (void)
|
|
2765 {
|
278
|
2766 #ifdef HAVE_MSG_SELECT
|
|
2767 windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
|
|
2768 assert (windows_fd>=0);
|
|
2769 FD_SET (windows_fd, &input_wait_mask);
|
|
2770 /* for some reason I get blocks on the signal event pipe, which is
|
|
2771 bad...
|
|
2772 signal_event_pipe_initialized = 0; */
|
|
2773 #endif
|
|
2774
|
213
|
2775 event_stream = mswindows_event_stream;
|
223
|
2776
|
|
2777 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
|
|
2778 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
|
213
|
2779 }
|