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