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