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