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