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