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