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