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